What problem does it solve?
React 18 silently changed how setState behaves in async contexts: calls inside setTimeout, Promise .then()/.catch(), async/await, and native event handlers are now batched instead of triggering immediate re-renders. This causes silent bugs in class components that read this.state after an await, and breaks tests that assert intermediate states synchronously.
Core Features & Use Cases
- Diagnostic Decision Tree: Classify any broken async setState pattern into Category A (silent this.state read bug), Category B (independent setState calls needing refactor), or Category C (intermediate render must be visible, requiring flushSync).
- Before/After Fix Patterns: Concrete code rewrites for each category, including multi-step conditional chains, Promise chains, setTimeout autosave flows, and broken test assertions fixed with waitFor.
- flushSync Usage Guide: Exact import syntax (from react-dom, not react), when to use it, when not to, and performance warnings against overuse.
- Use Case: After upgrading a codebase to React 18, a loading spinner never appears and a conditional update silently never fires. Use this Skill to identify it as a Category A bug and rewrite the method to remove the this.state read after await.
Quick Start
Ask the AI to diagnose why a class component's setState calls inside an async method stopped re-rendering after upgrading to React 18.