juniorReact Hooks
What is useEffect and when should it be used?
Updated May 6, 2026
Short answer
useEffect handles side effects in React components like API calls and subscriptions.
Deep explanation
It runs after rendering and can optionally depend on state/props. It replaces lifecycle methods like componentDidMount and componentDidUpdate.
Real-world example
Fetching user data when a page loads.
Common mistakes
- Forgetting dependency arrays causing infinite loops.
Follow-up questions
- What is the difference between mount and update effects?
- What happens if dependency array is omitted?