Componentwillunmount Hooks React Code Example


Example 1: componentdidmount hooks


For componentDidMount
useEffect(() => {
// Your code here
}, []);

For componentDidUpdate
useEffect(() => {
// Your code here
}, [yourDependency]);

For componentWillUnmount
useEffect(() => {
// componentWillUnmount
return () => {
// Your code here
}
}, [yourDependency]);

Example 2: componentdidupdate in hooks


const App = props => {
const didMountRef = useRef(false)
useEffect(() => {
if (didMountRef.current) {
doStuff()
} else didMountRef.current = true
}
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android SDK Location Should Not Contain Whitespace, As This Cause Problems With NDK Tools