I think you've made a mistake (or I didn't get your point) :
useEffect(callbackFunction) in here, callbackFunction is not executed only once after the first render but after each render ;
and useEffect(callbackFunction, []) is not the same as useEffect(callbackFunction) , when you provide an empty array it's precisely in this case that your function is executed only once.
Some other writing mistakes with mixed up terms : myVar , var1 , var2 , var , myObject .
The post is full with bad advice. It's a good attempt, but a bad resource.
For example:
In example 3 you must always use primitives as dependencies never reference types such as *Functions, Objects or Arrays. Use only string, boolean, number.
You can use whatever you want as a dependency in the second argument of a useEffect hook, but if you want it to work as intended, the value must be stable: that is, not be regenerated each render. You can use functions, objects, and arrays.
Hi Derk Jan,
Thank you for your feedback.
I updated this post so I removed that wrong typos and I'm trying to make my point clearer.
About the primitives as dependencies I'm trying to explain that most of the devs are simply filling in this parameter and are not aware about why.
Let me know if you have any resource that explains better about this specific part.
This is my first post so I was trying to make it fine instead of make it perfect because I procrastinated it for a long time.
Thank you for helping me to make it better.
Hi calag4n, thank you for your feedback.
I didn't know about this difference between with /without array so thank you very much for teaching me that.
I updated the post.
I think you've made a mistake (or I didn't get your point) :
useEffect(callbackFunction)
in here, callbackFunction is not executed only once after the first render but after each render ;and
useEffect(callbackFunction, [])
is not the same asuseEffect(callbackFunction)
, when you provide an empty array it's precisely in this case that your function is executed only once.Some other writing mistakes with mixed up terms : myVar , var1 , var2 , var , myObject .
Nice post otherwise 👍️
The post is full with bad advice. It's a good attempt, but a bad resource.
For example:
You can use whatever you want as a dependency in the second argument of a
useEffect
hook, but if you want it to work as intended, the value must be stable: that is, not be regenerated each render. You can use functions, objects, and arrays.Hi Derk Jan,
Thank you for your feedback.
I updated this post so I removed that wrong typos and I'm trying to make my point clearer.
About the primitives as dependencies I'm trying to explain that most of the devs are simply filling in this parameter and are not aware about why.
Let me know if you have any resource that explains better about this specific part.
This is my first post so I was trying to make it fine instead of make it perfect because I procrastinated it for a long time.
Thank you for helping me to make it better.
Hi calag4n, thank you for your feedback.
I didn't know about this difference between with /without array so thank you very much for teaching me that.
I updated the post.
Glad to help 😊