Sobes.tech
Junior

Name the components of the React component lifecycle.

sobes.tech AI

Answer from AI

  • mounting
    • constructor(): initializes state and binds context.
    • static getDerivedStateFromProps(): synchronizes internal state with props.
    • render(): constructs the DOM.
    • componentDidMount(): performs effects after the first render (API requests, subscriptions).
  • updating
    • static getDerivedStateFromProps(): (called during prop updates)
    • shouldComponentUpdate(): optimizes rendering (determines if re-rendering is needed).
    • render(): re-renders the DOM.
    • getSnapshotBeforeUpdate(): gets DOM data before update (e.g., scroll position).
    • componentDidUpdate(): performs effects after update (DOM changes, re-requests).
  • unmounting
    • componentWillUnmount(): cleans up resources before component removal (cancels subscriptions, timers).
  • error handling
    • static getDerivedStateFromError(): updates state when an error occurs in a child component.
    • componentDidCatch(): logs errors.