What are React lifecycle methods?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex React.js topics. It also reveals how well you can explain technical ideas to non-experts.
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: componentDidMount → useEffect(() => { ... }, []); componentDidUpdate → useEffect(() => { ... }, [deps]); componentWillUnmount → cleanup returned from useEffect. Modern React prefers function components — class components are considered legacy but are not deprecated.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong React.js candidates.