I am trying to understand if it's against React's best-practices to use return in useEffect, to avoid some logic from being executed. So far in documentation I only see it being used for clean-ups.
I have a candidate which wrote similar logic:
useEffect(() => {
if (foo === 'bar') {
baz();
return;
}
xyz();
,[foo]);
Ideally should be one of:
1.
useEffect(() => {
if (foo === 'bar') {
baz();
} else {
xyz();
}
,[foo]);
- two smaller useEffects
- logic separated from useEffect, and is conditional
However, to not have this opinion based. I am trying to find articles on this best-practice? PS. Official React docs do NOT have this kind of approach used ANYWHERE, or mention it other than a clean-up function.