Created
August 28, 2019 10:26
-
-
Save infinitypaul/1f7942bbf3683fefd97bec5f871a819f to your computer and use it in GitHub Desktop.
This file contains 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
const MyComponent = props => { | |
const innerFunction = useCallback(() => { | |
// do something! | |
}); | |
useEffect(() => { | |
innerFunction(); | |
// The effect calls innerFunction, hence it should declare it as a dependency | |
// Otherwise, if something about innerFunction changes (e.g. the data it uses), the effect would run the outdated version of innerFunction | |
}, [innerFunction]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment