Awesome Reviewers

Reviewer · React

Refs and effect side-effects

Refs must never be read or written during render; doing so breaks React's rendering model and can produce stale or inconsistent UI. If a value needs to be computed or validated based on changing props/state, do that work in an effect, event handler, or in the state/store update logic itself, not inline in the render body. For example, instead of falling...

Instruction

Refs must never be read or written during render; doing so breaks React’s rendering model and can produce stale or inconsistent UI. If a value needs to be computed or validated based on changing props/state, do that work in an effect, event handler, or in the state/store update logic itself, not inline in the render body. For example, instead of falling back to ref.current when a derived value is invalid during render, compute and store the fallback as part of the dispatch/update logic so render only reads plain state.

When implementing debouncing, throttling, or deferred updates, prefer built-in React primitives (e.g. useDeferredValue) over hand-rolled setTimeout/useRef combinations whenever they satisfy the requirement. If a manual timer-based approach is still necessary (e.g., to further smooth out rapid updates), only add a cleanup effect when the resource could outlive the component in a harmful way (e.g., it holds an interval, subscription, or external resource that would leak or fire unwanted side effects after unmount). A one-shot setTimeout that just updates local/dispatched state will naturally expire and generally does not require explicit cleanup unless the resulting dispatch after unmount is itself problematic.

In short: keep render pure (no ref reads/writes), push side-effectful logic into effects/handlers/store updates, prefer existing React APIs for async UI patterns, and reserve effect cleanup for resources that genuinely need to be canceled on unmount.