I sort of noticed that alot of people do not know the difference between the useEffect and useLayoutEffect hooks in React. Finding a use case for...
For further actions, you may consider blocking this person and/or reporting abuse
Thank you for the simple and to the point information!
I'm glad you find it helpful.
@emmanuelthecoder , I read your article, Actually yesterday I thought I would write article of
UseEffect
andUseLayoutEffect
but........,after reading your article I thought not necessary to write article on that topic because you can clear all points in Very Simple Manner.
Another thing is that
UseEffect
andUseLayoutEffect
is called after render method called means whenver any DOM mutation occured but if we don't pass array dependency so it's called in infinite loop. That thing applied on both UseEffect and UseLayoutEffect.So, It's necessary to pass Empty array dependency in the hook as second argument
Thanks for the kind words and the additional point. I'm glad you found the article helpful.
Would be glad if you could give me a follow here and share the article.
Yes, yes, but @doshiparth642 has a good point, your article is incorrect in the sense that it doesn't follow the recommended practices.
An
useEffect
oruseLayoutEffect
must always have a dependency array, since you don't want it to run every time.@doshiparth642 pointed that out and you replied with a copy-paste answer, instead of fixing your code.
This article could have been better written by OpenAI (or at least checked by it).
You don't need to change the code, but i leave this comment here for posterity pointing out your apparent inability to correct things :) or to answer to comments
Hi @svbzctvxapkkyc
Thank you for pointing out the apparent oversight. I have updated the article.
"...Pointing out your apparent inability to correct things..." — if that was the case for me, I could simply hide your comment. But that's not it as I am happy to take corrections and effect them — no one is an island of knowledge.
Also, at the time of writing this article, ChatGPT wasn't released yet but I guess you wouldn't know this.
You're right, 2022 not 2023 :) Sorry for that oversight.
Thank you for the correction! :)
Thanks, the explanation is clear, but about this sentence:
it depends on the dependency array of the useEffect.
Yes! by default, React runs side-effect on every render but this can be customized by passing in an array of dependencies.
Seems it's your first week with React, Emmanuel. How's the progress going? :)
Ok, I know I had a case on my previous project where it was better to use useLayoutEffect over useEffect. Thanks.