How to perform ComponentDidMount, ComponentDidUpadte and ComponentUnmount in functional component

--

In React functional components, you can achieve the equivalent behavior of componentDidMount, componentDidUpdate, and componentWillUnmount lifecycle methods using the useEffect hook.

1 componentDidMount

useEffect(() => {

console.log(“Mount”)},[])

2 componentDidUpdate

useEffect(() => {

console.log(“Mount”)},[setAnyVariableName])

3 componentWillUnmount

useEffect(() => { return()=>{ console.log(“Mount”)

}

},[])

--

--

Vineet Mishra

Full Stack Developer at CCR Tech, I write about Mobile/Web Development and Deployment, and Interview Q & A