I hate how useEffect works.
useEffect
I'd prefer having lifecycle back.
My main reason?
Is a hook that has many concerns. I prefer to think of functions as things that does only one thing right and nothing else.
I've tried a PoC for the project I'm working on and useEffect had very tricky behaviors at first.
Just think a bit about it:
If you want to do something on every render:
useEffect(<function>)
If you want to trigger something based on change of only one variable:
useEffect(<function>, [variableToWatch])
If you want to trigger on mount:
useEffect(<function>, [])
If you want to trigger something on unmount:
useEffect( () => { return () => { // Some cleanup code here } }, []);
And what about cleanup functions?
Do you think they behave the same on all the cases?
Oh, my dear friend let me tell you that you're totally wrong.
As I said before, this works on component unmount:
And being honest I don't know when/why is the cleanup function is called here:
useEffect( () => { return () => { // Some cleanup code here } };
That's my two cents about it.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I hate how
useEffect
works.I'd prefer having lifecycle back.
My main reason?
Is a hook that has many concerns. I prefer to think of functions as things that does only one thing right and nothing else.
I've tried a PoC for the project I'm working on and useEffect had very tricky behaviors at first.
Just think a bit about it:
If you want to do something on every render:
If you want to trigger something based on change of only one variable:
If you want to trigger on mount:
If you want to trigger something on unmount:
And what about cleanup functions?
Do you think they behave the same on all the cases?
Oh, my dear friend let me tell you that you're totally wrong.
As I said before, this works on component unmount:
And being honest I don't know when/why is the cleanup function is called here:
That's my two cents about it.