react useEffect when configuring dependency list to [] - equivalent to to componentMount

 This basically means that the component will load the first time and do it things 


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

Probably relevant to other scenario as well - this shows an example but maybe not realistic one - that if you forget to clean, there could be some side effects.  

useEffect(() => {
    console.log("calling effects");
    const itv = setInterval(() =>
    {
      setCount(count + 1)
    }, 3000);

    return () => {
       clearInterval(itv);
    }
   }, [count]);

Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type