Skip to content

Commit

Permalink
Do not setState when unmounted in OverflowTooltip
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
  • Loading branch information
freben committed Dec 21, 2021
1 parent 2d6f65e commit 10e5f9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/smooth-news-melt.md
@@ -0,0 +1,5 @@
---
'@backstage/core-components': patch
---

Do not `setState` when unmounted in `OverflowTooltip`
Expand Up @@ -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'];
Expand All @@ -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 (
Expand Down

0 comments on commit 10e5f9d

Please sign in to comment.