Or you can directly skip using state and compute the condition inside the jsx.
Take away:
Infinite loops in React often come from state updates in the render phase. Keep renders pure, use useEffect for side effects, and skip unnecessary state for computed values. Your components will thank you!
Move state updates to useEffect, which runs after render:
Why it works: useEffect ensures state updates happen outside the render phase, preventing loops. The [data] dependency means it only runs when data changes.
Common use cases:
- Deploying code to a server
- Managing databases remotely
- Copying files between machines
- Running scripts without leaving your terminal