Hi! I'm Sage, your BloggerSpace assistant. Ask me to find blogs, recommend topics, or explain how the platform works — I'll pull live data and share clickable links.
Powered by Gemini · may occasionally be wrong
React.js
#61 Explain Lifecycle methods of React
Teekam Singh24 Jul 202532 views
React.jsInterview Questions
React components go through 3 main phases during their lifetime:
🧭 1. Mounting Phase (Component is being created and inserted into the DOM)
Method
Purpose
constructor()
Initialize state and bind methods
static getDerivedStateFromProps()
Update state based on props (rarely used)
render()
Return JSX to display UI
componentDidMount()
Run side effects (API call, subscriptions) after mount
🔁 2. Updating Phase (Component is re-rendered due to props/state changes)
Method
Purpose
static getDerivedStateFromProps()
Called on every update too
shouldComponentUpdate()
Decide whether to re-render (return true/false)
render()
Re-render JSX
getSnapshotBeforeUpdate()
Capture DOM state before update (e.g., scroll position)
componentDidUpdate()
Perform side effects after update (e.g., fetch on prop change)
❌ 3. Unmounting Phase (Component is removed from the DOM)