How to perform ComponentDidMount, ComponentDidUpadte and ComponentUnmount in functional component

Vineet Mishra
Aug 1, 2023

--

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

SDE 2 at Accelya , I write about Mobile/Web Development and Deployment, and Interview Q & A