Explain various lifecycle methods of React components

Posted by Andre Scott | Updated on
  • componentDidMount() – Executes on the client side after the first render
  • componentDidUpdate() – Called immediately after rendering takes place in the DOM
  • componentWillMount() – Executes immediately before rendering starts on both the client-side and the server-side
  • componentWillReceiveProps() – Invokes when props are received from the parent class and before another render is called
  • componentWillUnmount() – Used to clear up the memory space. Called right after the component is unmounted from the DOM
  • componentWillUpdate() – Called immediately before rendering takes place in the DOM
  • shouldComponentUpdate() – Returns either true or false. Though false by default, needs to be set to return true if the component needs to be updated

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers