react
✓Verified·Scanned 2/18/2026
Build fast, accessible React apps with hooks, state, and component patterns.
from clawhub.ai·v7924891·3.2 KB·0 installs
Scanned from 1.0.0 at 7924891 · Transparency log ↗
$ vett add clawhub.ai/ivangdavila/react
React Production Rules
Common Mistakes
{count && <Component />}renders "0" when count is 0 — always use{count > 0 && <Component />}for numeric conditions- Never mutate state directly (
array.push()thensetState(array)) — React won't detect the change. Always spread:setState([...array, item]) - Keys generated during render (
key={Math.random()}) destroy and recreate components every render — generate stable IDs when data is created - Uninitialized controlled inputs (
useState()without default) flip between controlled/uncontrolled — always initialize with empty string or appropriate default
Hooks Traps
useEffectcallback cannot be async directly — define async function inside the effect and call it- Missing cleanup in effects causes memory leaks — return cleanup function for subscriptions, intervals, and event listeners
- Dependencies array with objects/arrays triggers on every render (new reference each time) — memoize with
useMemoor extract primitive values useStatesetter with same reference won't trigger re-render — for objects/arrays, always create new reference
Performance
- Sequential awaits create waterfalls — use
Promise.all([fetchA(), fetchB()])for independent requests - Barrel imports (
import { X } from '@/components') pull entire module — use direct path imports for tree-shaking - Expensive computations in render body recalculate every render — wrap in
useMemowith proper dependencies - Use
startTransitionfor non-urgent UI updates (filtering, sorting large lists) — keeps input responsive while heavy renders process in background - Use
useRefinstead ofuseStatefor values that don't need to trigger re-renders (timers, previous values, DOM measurements)
State Architecture
- Colocate state as close as possible to where it's used — lifting state too high causes unnecessary re-renders in the entire subtree
- Derive values from existing state instead of syncing with useEffect — computed values don't need their own state
- When multiple state updates happen together, use
useReducer— prevents impossible state combinations that separateuseStatecalls allow - URL search params are state too — use them for filter/sort/pagination state so users can share and bookmark
Forms (React 19+)
- Prefer form actions over useEffect for mutations — actions handle pending states, errors, and optimistic updates built-in
- Use
useActionStatefor form submission status — replaces manual loading/error state management useOptimisticupdates UI immediately before server confirms — revert automatically on error
Common Mistakes
- Fetching data in useEffect without abort controller — race conditions when component remounts or deps change fast
- Returning objects from custom hooks without memoizing — consumers re-render on every call even if data hasn't changed
- Using index as key in lists that reorder, filter, or insert — causes subtle bugs where component state gets attached to wrong items