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

The specified initialization vector (IV) does not match the block size for this algorithm