Last active
October 2, 2020 09:27
-
-
Save igmoweb/4a39891fede51a850428704d82ba4a7d to your computer and use it in GitHub Desktop.
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
// Always run | |
useEffect( () => { | |
// code to run | |
} ); | |
// As componentDidMount (run once) | |
useEffect( () => { | |
// code to run | |
}, [] ); | |
// Run only when attr changes | |
useEffect( () => { | |
// code to run | |
}, [ attr ] ); | |
// Run only when component updates (componentDidUpdate) | |
const didMountRef = useRef( false ); | |
useEffect( () => { | |
if (didMountRef.current) { | |
// code to run | |
} else didMountRef.current = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment