Middle
What are component lifecycle methods? List the main ones.
sobes.tech AI
Answer from AI
Component lifecycle methods are special functions that are called at different stages of a component's existence in the UI. They allow managing state, performing side effects, and optimizing performance.
The main lifecycle methods in React (class components) include:
constructor— component initialization.componentDidMount— called after the component is mounted, suitable for data loading.shouldComponentUpdate— controls whether the component should re-render.componentDidUpdate— called after the component updates.componentWillUnmount— resource cleanup before the component is removed.
In functional components, these stages are implemented through hooks, such as useEffect.