React | useEffect Hooks | Interview Questions | Very Helpful

Let's dive right in with some fascinating facts about useEffect hook:-

case 1 :- what happens, when the dependencies array is not present.

useEffect (()=> {
consloe.log("useEffect called ");
  });

👉 if there is no dependencies array that means useEffect is called on every component renderd.

case 2 :- what happens, when the dependencies array is empty.

useEffect (()=> {
consloe.log("useEffect called ");
  }, [ ]);
  

👉 if the dependencies array is empty that means useEffect is called on initial render (just once).
Here, "just once " means when the component rendered from the first time.

case 3 :- what happens, when the dependencies array is [x].

useEffect (()=> {
consloe.log("useEffect called ");
  }, [x]);

👉 if the dependencies array is [x] that means useEffect is called on everytime x is updated.

Cheers,
Akash Keshri

Don't forget to upvote this post if it has helped you!!!

Comments (2)