How do class lifecycle methods map to hooks?
constructor maps to useState initial values. componentDidMount maps to useEffect with an empty dependency array. componentDidUpdate maps to useEffect with dependencies. componentWillUnmount maps to the cleanup function returned from useEffect.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in React Class Component Lifecycle Methods Explained With Examples
Three phases: mounting when the component is added to the DOM, updating when it re-renders due to state or props changes, and unmounting when it is removed. Each phase has lifecycle methods that run at specific points.
It runs after the component is added to the DOM. You use it to fetch data, set up subscriptions, and start timers, similar to useEffect with an empty dependency array in functional components.
It runs right before the component is removed from the DOM. You use it to clean up subscriptions, timers, and listeners to prevent memory leaks, similar to the cleanup function returned from useEffect.
Still have questions?
Browse all our FAQs or reach out to our support team
