Back to all skills
Progress37 of 45
Re-rendersMedium

Use Functional setState Updates

When updating state based on the current state value, use the functional update form of setState instead of directly referencing the state variable. This prevents stale closures, eliminates unnecessary dependencies, and creates stable callback references.

reacthooksuseStateuseCallbackcallbacksclosures

Code Comparison

Incorrect (requires state as dependency):tsx
Correct (stable callbacks, no stale closures):tsx

Why This Matters

Impact: prevents stale closures and unnecessary callback recreations. This optimization is classified as MEDIUM priority for production applications.