componentDidMount runs once, after mount. componentDidUpdate runs after every update caused by state or props changes. They handle different moments in the component lifecycle.
React Lifecycle and Class Component Interview Questions
What is the difference between componentDidMount and componentDidUpdate?
The answer
More FAQs in React Lifecycle and Class Component Interview Questions
Mounting, updating, and unmounting. Mounting is when the component is added to the DOM, updating is when it re-renders due to state or props changes, and unmounting is when it is removed.
It runs after the component is added to the DOM. You fetch data, set up subscriptions, and start timers here. It maps to useEffect with an empty dependency array in functional components.
It runs right before the component is removed from the DOM. You clean up subscriptions, timers, and listeners here to prevent leaks. It maps to the cleanup function returned from useEffect.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.