Lifecycle Methods in Functional components
LIFECYCLE METHODS- REACT

Lifecycle Methods in Functional components

Lifecycle refers to the series of phases that a React component goes through from its creation, rendering and eventual removal from DOM.

While the traditional lifecycle methods are allowed for the class components, introduction of hooks has provided the most versatile way to manage behavior of functional components

There are 3 phases in React Component Lifecycle

1. Mounting

2. Updating

3. Unmounting

MOUNTING PHASE:

During Mounting phase component has been created and added to DOM. In this phase State has been initialized.

USESTATE hook allows to add state to your functional components.


Mounting- UseState Hook


UPDATING PHASE:

USEEFFECT hook allows to perform side effects (nothing but the tasks performed outside the component) For example , fetching data from API calls. It eliminates the need of constructor.


Updating Phase -UseEffect Hook

UNMOUNTING PHASE:

Unmounting phase, functional component will be removed from DOM.

By returning a function from useEffect hook, cleanup operations can be specified


Unmounting Phase - UseEffect Hook


Understanding the concept of hooks and using them appropriately will result in building efficient React applications.


Thats all about Lifecycle methods in Functional components


Thanks,

Sougandika L.

要查看或添加评论,请登录

Sougandika L的更多文章

  • Are you excited to know about Event Flow in Javascript ??

    Are you excited to know about Event Flow in Javascript ??

    Order in which event triggered on DOM nodes is called event flow. There are 2 types of events: 1.

  • Angular 18 feature - Zoneless Change Detection

    Angular 18 feature - Zoneless Change Detection

    One of the most significant changes is the introduction of zoneless change detection. Reason : To avoid unnecessary…

  • Difference between Subject and Observable

    Difference between Subject and Observable

    1.Subject can be provider as well as consumer.

  • Why do we need package.json

    Why do we need package.json

    Most of us are concerned or focused on the place where we write our code, whether it might be styling (css) or…

  • SIGNAL in Angular

    SIGNAL in Angular

    With Change detection, incase of any change in one of the components, it check for all the components and then render…

    1 条评论
  • Creating Reusable Components in Angular

    Creating Reusable Components in Angular

    Lets start with a basic button Here in the image we could see 3 different buttons with different names, different…

    3 条评论
  • Reactive forms in Angular

    Reactive forms in Angular

    Angular provides 2 ways to work with forms – 1. Template driven forms 2.

  • Angular -Download Data in Excel format

    Angular -Download Data in Excel format

    Hello everyone, One of the most common usecases now a days is printing the data. In this article we will be…

  • Why Array ? Its declaration in Javascript

    Why Array ? Its declaration in Javascript

    Array is a special variable which holds more than one value at a time. It stores the homogenous elements.

  • Scope: What does it exactly mean?

    Scope: What does it exactly mean?

    Hello everyone, This is Sougandika. Do you want to know what is scope? Be with me till the end and I am sure that this…

社区洞察