Skip to content

Commit

Permalink
Use Select: Make isMounted more informative.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Dec 20, 2019
1 parent dbeee12 commit b448c5c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/data/src/components/use-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -166,7 +166,7 @@ export default function useSelect( _mapSelect, deps ) {
} );

return () => {
isMounted.current = false;
isMountedAndNotUnsubscribing.current = false;
unsubscribe();
renderQueue.flush( queueContext );
};
Expand Down

0 comments on commit b448c5c

Please sign in to comment.