Merge pull request #8563 from backstage/freben/mount-state

Do not `setState` when unmounted in `OverflowTooltip`
This commit is contained in:
Fredrik Adelöw
2021-12-21 13:39:29 +01:00
committed by GitHub
2 changed files with 10 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/core-components': patch
---
Do not `setState` when unmounted in `OverflowTooltip`
@@ -18,6 +18,7 @@ import { makeStyles } from '@material-ui/core/styles';
import Tooltip, { TooltipProps } from '@material-ui/core/Tooltip';
import React, { useState } from 'react';
import TextTruncate, { TextTruncateProps } from 'react-text-truncate';
import { useMountedState } from 'react-use';
type Props = {
text: TextTruncateProps['text'];
@@ -40,10 +41,13 @@ const useStyles = makeStyles(
export function OverflowTooltip(props: Props) {
const [hover, setHover] = useState(false);
const isMounted = useMountedState();
const classes = useStyles();
const handleToggled = (truncated: boolean) => {
setHover(truncated);
if (isMounted()) {
setHover(truncated);
}
};
return (