What are React lifecycle methods?

Answer

React lifecycle methods are special methods in class components that run at specific points in a component's life. Mounting (component is added to the DOM): constructor()render()componentDidMount() (ideal for data fetching, subscriptions). Updating (state or props change): render()componentDidUpdate(prevProps, prevState) (run after updates, compare with prev to avoid infinite loops). Unmounting (component removed): componentWillUnmount() (cleanup: cancel requests, unsubscribe). Error handling: componentDidCatch(error, info) and static getDerivedStateFromError() — only available in class components. Function component equivalents with hooks: componentDidMountuseEffect(() => { ... }, []); componentDidUpdateuseEffect(() => { ... }, [deps]); componentWillUnmount → cleanup returned from useEffect. Modern React prefers function components — class components are considered legacy but are not deprecated.