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
Post a Comment