Originally published on CodingCush .
If your useEffect runs twice in development, React is usually doing it on purpose: Strict Mode deliberately runs your effects an extra time to help you find bugs before your users do. And if your useEffect runs forever in an endless loop, the cause is almost always the same — the effect changes something it also depends on, so React runs it again, which changes it again, and round you go. Neither behaviour means React is broken. Both are signals about how your effect is written, and both have clear, simple fixes once you can see the pattern.
Think of an effect like an assistant told to “keep this list fresh.” If your instructions rewrite the list every time they check it, they will never stop checking. Your job is to write instructions that finish.…