Created
August 14, 2019 10:15
-
-
Save milankinen/635b35f6f69d0c1b673ad81dfcf851a8 to your computer and use it in GitHub Desktop.
Modified useSubscription
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -23,8 +23,8 @@ export function useSubscription({ getCurrentValue, subscribe }) { | |
useEffect(() => { | |
let didUnsubscribe = false; | |
- | |
- const checkForUpdates = () => { | |
+ // NOTICE: value coming from subscription not from getCurrentValue !!! | |
+ const onValue = value => { | |
if (didUnsubscribe) { | |
return; | |
} | |
@@ -35,7 +35,7 @@ export function useSubscription({ getCurrentValue, subscribe }) { | |
) { | |
return prevState; | |
} | |
- const value = getCurrentValue(); | |
+ | |
if (prevState.value === value) { | |
return prevState; | |
} | |
@@ -43,8 +43,8 @@ export function useSubscription({ getCurrentValue, subscribe }) { | |
return { ...prevState, value }; | |
}); | |
}; | |
- const unsubscribe = subscribe(checkForUpdates); | |
- checkForUpdates(); | |
+ const unsubscribe = subscribe(onValue); | |
+ onValue(state.getCurrentValue()); | |
return () => { | |
didUnsubscribe = true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment