Skip to content

Instantly share code, notes, and snippets.

@infinitypaul
Created August 28, 2019 09:43
Show Gist options
  • Save infinitypaul/5743da650cbb75f00a1036b646cc0bf8 to your computer and use it in GitHub Desktop.
Save infinitypaul/5743da650cbb75f00a1036b646cc0bf8 to your computer and use it in GitHub Desktop.
const MyComponent = props => {
const innerFunction = () => {
// 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