๐ React useEffect Hook
The useEffect Hook allows you to perform side effects in your React components.
What Are Side Effects?
Side effects are operations that affect something outside the scope of the function being executed. Examples include:
- Fetching data from an API
 - Directly updating the DOM
 - Setting up timers (e.g., 
setTimeout,setInterval) - Subscribing to events
 
Basic Syntax
- The first argument is the function that runs the side effect.
 - The second argument is optional, and it controls when the effect should run.
 
Timer Example
- To make the effect run only once (on mount), pass an empty dependency array ([]):
 
Timer (Wrong Way)
What's wrong?
This code keeps running setTimeout on every render, causing the counter to update infinitely.
Run useEffect When Dependencies Change
Tips
- Always specify the dependencies clearly to avoid bugs.
 - Clean up side effects when necessary to prevent memory leaks.
 - Avoid using async directly in 
useEffect- use an inner function instead.