Skip to content

Commit

Permalink
Only setState if the component is still mounted (#30667)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley authored Apr 9, 2021
1 parent 087fca4 commit 2e6676a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/components/src/slot-fill/bubbles-virtually/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import useSlot from './use-slot';

function useForceUpdate() {
const [ , setState ] = useState( {} );
return () => setState( {} );
const mounted = useRef( true );

useEffect( () => {
return () => {
mounted.current = false;
};
}, [] );

return () => {
if ( mounted.current ) {
setState( {} );
}
};
}

export default function Fill( { name, children } ) {
Expand Down

0 comments on commit 2e6676a

Please sign in to comment.