State Management with useState & useEffect Hooks
Manage component lifecycle, state persistence, side-effect cleanup, and custom React hooks.
React Hook Rules & Effect Cleanup
### Rules of React Hooks
1. **Call Hooks Only at the Top Level**: Never invoke hooks inside loops, conditional `if` statements, or nested functions.
2. **Call Hooks Only from React Functions**: Call hooks strictly inside functional components or custom hooks.
---
### useEffect Synchronization Lifecycle
`useEffect(setup, dependencies)` synchronizes components with external side-effects (fetching data, subscribing to browser events). Returning a cleanup function prevents memory leaks when components unmount.