DEV Community

fardinh136
fardinh136

Posted on

Component Life Cycle discussion.

 Components are created, then grows by updating, and then die. This is referred to as a component lifecycle. There are different lifecycle methods that React provides at different phases of a component's life.
Lifecycle methods are special methods built-in to React, used to operate on components throughout their duration in the DOM. For example, when the component mounts, renders, updates, or unmounts. The most important lifecycle method is the render method.
Every React Component has a lifecycle of its own, lifecycle of a component can be defined as the series of methods that are invoked in different stages of the component's existence.
The componentWillMount() method is the first to be called. It's invoked once and immediately before the initial rendering occurs, hence before React inserts the component into the DOM.
So lifecycle can be handy sometimes when we don't want React to render our state or prop changes. Anytime setState() is called, the component re-renders by default. The shouldComponentUpdate() method is used to let React know if a component is not affected by the state and prop changes.

Top comments (0)