Menu

React useEffect Hooks
📰

React useEffect Hooks

DEV Community: react·Vishnu Priya S·about 10 hours ago
#4VjAvyNT
#devtoreact#devto#dev#runs#array
Reading 0:00
15s threshold

Vishnu Priya S

It initially re-render rather than re-rendering of everytime and you control whether it runs again using the dependency array.

eg:
useEffect(() => {
console.log("Runs only once when the component first loads");
}, []);

-> when specific values change: Put those variables inside the array.
eg:

useEffect(() => {
console.log("Runs on first load, and ONLY when 'userId' changes");
}, [userId]);