React Life-Cycle Methods

88 views 7 slides Dec 18, 2023
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

There are three categories of lifecycle methods: mounting, updating, and unmounting.


Slide Content

React Life-Cycle Methods
Kavindu Samarasinghe (B.Sc)
Software Engineer

REACT LIFE-CYCLE METHODS
Mounting Updating Unmounting

Render
REACT LIFE-CYCLE METHODS
Mounting Updating Unmounting

Render
Constructor
static getDerivedStateFromProps
shouldComponentUpdate
getSnapshotBeforeUpdate
componentDidUpdate
componentDidMount
Mounting Updating Unmounting
componentWillUnmount
Props
Change
setState() forceUpdate()
REACT LIFE-CYCLE METHODS

REACT LIFE-CYCLE METHODS - MOUNTING
constructor(props)
Initializes state and binds event handlers.
componentDidMount()
Called after the first render, ideal for fetching data, setting up subscriptions, or integrating
with DOM APIs.
getDerivedStateFromProps(props, state) (React 16.3+)
Automatically updates state based on changes in props.

REACT LIFE-CYCLE METHODS - UPDATING
shouldComponentUpdate(nextProps, nextState)
Determines if a component should re-render based on changes in props or state.
render()
Generates the component's HTML output based on its state and props.
componentDidUpdate(prevProps, prevState)
Called after the component re-renders, useful for side effects like DOM manipulation or
state updates based on the previous state.

REACT LIFE-CYCLE METHODS - UNMOUNTING
componentWillUnmount()
Called before a component is removed from the DOM, useful for cleaning up resources like
subscriptions or timers.