how to do component did mount in react hooks code example
Example 1: use effect like component did mount
useEffect(() => {
console.log('I am the new componentDidMount')
}, [])
// Don't forget the empty array at the end
Example 2: componentdidupdate in hooks
const App = props => {
const didMountRef = useRef(false)
useEffect(() => {
if (didMountRef.current) {
doStuff()
} else didMountRef.current = true
}
}