Skip to content

Instantly share code, notes, and snippets.

@infinitypaul
Created August 28, 2019 10:26
Show Gist options
  • Save infinitypaul/1f7942bbf3683fefd97bec5f871a819f to your computer and use it in GitHub Desktop.
Save infinitypaul/1f7942bbf3683fefd97bec5f871a819f to your computer and use it in GitHub Desktop.
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