From b448c5c1d03308986cfa6ef0d0e84b1b1fd08fe1 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Fri, 20 Dec 2019 19:20:34 -0300 Subject: [PATCH] Use Select: Make `isMounted` more informative. --- packages/data/src/components/use-select/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/data/src/components/use-select/index.js b/packages/data/src/components/use-select/index.js index 8ded2809fda124..97b8e207dd11dc 100644 --- a/packages/data/src/components/use-select/index.js +++ b/packages/data/src/components/use-select/index.js @@ -92,7 +92,7 @@ export default function useSelect( _mapSelect, deps ) { const latestIsAsync = useRef( isAsync ); const latestMapOutput = useRef(); const latestMapOutputError = useRef(); - const isMounted = useRef(); + const isMountedAndNotUnsubscribing = useRef(); let mapOutput; @@ -118,7 +118,7 @@ export default function useSelect( _mapSelect, deps ) { latestMapSelect.current = mapSelect; latestMapOutput.current = mapOutput; latestMapOutputError.current = undefined; - isMounted.current = true; + isMountedAndNotUnsubscribing.current = true; // This has to run after the other ref updates // to avoid using stale values in the flushed @@ -132,7 +132,7 @@ export default function useSelect( _mapSelect, deps ) { useIsomorphicLayoutEffect( () => { const onStoreChange = () => { - if ( isMounted.current ) { + if ( isMountedAndNotUnsubscribing.current ) { try { const newMapOutput = latestMapSelect.current( registry.select, @@ -166,7 +166,7 @@ export default function useSelect( _mapSelect, deps ) { } ); return () => { - isMounted.current = false; + isMountedAndNotUnsubscribing.current = false; unsubscribe(); renderQueue.flush( queueContext ); };