{"success":true,"name":"don-t-sprinkle-react-memo-and-usecallback-fix-state-placemen","description":"React app feels slow and you're reaching for memo/useCallback/useMemo","category":"ai-brimind","path":"ai-brimind/don-t-sprinkle-react-memo-and-usecallback-fix-state-placemen/SKILL.md","file":"SKILL.md","content":"---\nname: don-t-sprinkle-react-memo-and-usecallback-fix-state-placemen\ndescription: \"React app feels slow and you're reaching for memo/useCallback/useMemo\"\n---\n\n# Don't Sprinkle React memo and useCallback: Fix State Placement First, Memoize After Measuring\n\n## When to use\nProject is React, and you're about to wrap components in memo or hooks in useCallback/useMemo to fix re-renders or perceived slowness.\n\n## Example request\nTyping in one input re-renders the whole page → the input's state lives at the top; moving state down to where it's used ends the cascade, no memo needed. — memo added but the component still re-renders → an inline object or function prop is new every render, defeating memo; memoization only works when inputs are actually stable. — useCallback wrapped around everything 'for performance' → the code is harder to read and nothing measured got faster; premature memoization is complexity with no payoff. — List of 5,000 rows is slow → no amount of memo saves rendering 5,000 DOM nodes; list virtualization is the actual mechanism for that problem.\n\n## Instructions\nAct as a doctor who refuses to prescribe before diagnosing: memo is medicine for a measured disease, not a vitamin. When React feels slow or re-renders bother you: 1) Measure first with the React profiler — find WHICH components re-render, how often, and how expensive each render actually is; cheap re-renders are usually fine and need nothing. 2) Fix structure before adding memoization: move state down to the smallest component that uses it, or pass expensive subtrees as children so they don't re-render with the stateful parent — state placement solves most 'everything re-renders' cases for free. 3) Only reach for memo/useMemo/useCallback for a component or computation the profiler proved expensive, and then check its props are genuinely stable — an inline object, array, or arrow function prop makes memo useless. 4) Classify the real problem: too many renders (structure), expensive single render (memoize the costly part), or too much DOM (virtualize the list) — each has a different correct tool. 5) Re-measure after the change; if the numbers didn't move, remove the memoization. If you haven't profiled, don't touch anything yet. Only add memoization once the profiler confirms the specific hotspot, and explain why the fix addresses the measured cause instead of decorating the code with hopeful wrappers.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #965\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}