From 7b2f69d227582eebb938c1e931e88abeb1029cc9 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 9 Apr 2021 14:32:37 +0100 Subject: [PATCH] Only setState if the component is still mounted --- .../src/slot-fill/bubbles-virtually/fill.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/components/src/slot-fill/bubbles-virtually/fill.js b/packages/components/src/slot-fill/bubbles-virtually/fill.js index 38390ab28954c2..51a141ca2e2dc0 100644 --- a/packages/components/src/slot-fill/bubbles-virtually/fill.js +++ b/packages/components/src/slot-fill/bubbles-virtually/fill.js @@ -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 } ) {