Explain life Cycle of React JS Component ?

devquora
devquora

Posted On: May 29, 2024

 

React JS Component Lifecycle

Each component has several “lifecycle methods” that you can override to run code at particular times in the process. Methods prefixed with will are called right before something happens, and methods prefixed with did are called right after something happens.

Mounting

These methods are called when an instance of a component is being created and inserted into the DOM:

  • constructor()
  • componentWillMount()
  • render()
  • componentDidMount()

Updating

An update can be caused by changes to props or state. These methods are called when a component is being re-

rendered:

  • componentWillReceiveProps()
  • shouldComponentUpdate()
  • componentWillUpdate()
  • render()
  • componentDidUpdate()

Unmounting

This method is called when a component is being removed from the DOM:

  • componentWillUnmount()

Other APIs

Each component also provides some other APIs:

  • setState()
  • forceUpdate()

Class Properties

  • defaultProps
  • displayName

Instance Properties

  • props
  • state

Source: https://facebook.github.io/react/docs/react-component.html

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    React Js Interview Questions

    What is ReactJS ?

    ReactJS, created by Facebook, is a JavaScript library for crafting dynamic, stateful, and reusable user interface components. It's renowned for simplifying the presentation layer of web and mobile app..

    React Js Interview Questions

    List some advantages of ReactJS ?

    React.js offers efficiency with its virtual DOM, simplifies JavaScript with JSX, provides developer tools, enhances SEO, and facilitates UI test cases effortlessly...

    React Js Interview Questions

    What are Components in ReactJS ?

    React components divide UI into reusable pieces, akin to JavaScript functions. They accept props and return elements for screen rendering. Below is an ES6 class-based component showcasing a welcome me..