I was debating with a collegue today about using the "return
" key in a useEffect
to stop code execution. I have learned that using return
should only be done in a cleanup.
The issue:
useEffect(() => {
if (stateCondition) {
//do fancy stuff
return;
}
// more code to execute if condition is not met
}, [props]);
The way I see this is that we should perhaps have yet another useEffect
that only execute if the state is false and not use the "return
" as above.
I am trying to find some documentation to support my claim but so far I have not been able to.
What I am looking for:
Am I right here? is there documentation that supports my claim or the other way arround?