What are Lifecycle methods? ReactJS Interview Question

Functions that called while the component is rendered for the first time (mount), or about to be removed from the DOM (unmount).

  1. componentWillMount()// called before component rendered
  2.  render()// comment box is mounted
  3. Component waits for API response and when it's received, setState() is called, causing render() to be called again.
  4.  componentDidMount()//called when component done rendering. this._fetchComments() triggered every 5 seconds
  5. componentWillUnmount()// called when the component is about to be removed from the DOM, and clears the fetchComment timeout
Whenever a component instance updates, it automatically calls all five of these methods, in order.



Contact Form