Component lifecycle methods

In React, each component has its own specific callback function. These callback functions play an important role when we are thinking about DOM manipulation or integrating other plugins in React (jQuery). Let's look at some commonly used methods in the life cycle of a component:

  • getInitialState(): This method will help you to get the initial state of a component.
  • componentDidMount: This method is called automatically when a component is rendered or mounted for the first time in DOM. While integrating JavaScript frameworks, we'll use this method to perform operations such as setTimeout or setInterval, or send AJAX requests.
  • componentWillReceiveProps: This method will be used to receive new props.

    Note

    There is no alternative method as, componentWillReceiveState. If we need to perform operations on state changes then we use componentWillUpdate.

  • componentWillUnmount: This method is invoked before the component is unmounted from DOM. Cleanup the DOM memory elements which are mounted in the componentDidMount method.
  • componentWillUpdate: This method is invoked before updating a new props and state.
  • componentDidUpdate: This is invoked immediately when the component has been updated in DOM.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset