Common anti-patterns: storing derived data in state and syncing it with effects, using effects for event logic ("you might not need an effect"), mutating state or props, unstable or index keys in dynamic lists, defining components inside other components, copying props into state, giant components and contexts, premature or blanket memoization (or none where it matters), prop drilling through many layers, fetching in effects without cleanup or caching, calling hooks conditionally, and side effects during render. Most trace back to fighting React's model of pure rendering from minimal state.
// Anti-pattern
const [fullName, setFullName] = useState('');
useEffect(() => setFullName(`${first} ${last}`), [first, last]);
// Better: compute during render
const fullName = `${first} ${last}`;
The effect version renders twice, briefly shows stale data, and creates two sources of truth.
// Anti-pattern: reacting to a state change you caused yourself
useEffect(() => { if (submitted) post('/api', form); }, [submitted]);
// Better: do it in the handler
async function handleSubmit() { await post('/api', form); }
Effects are for synchronizing with external systems, not for chaining state updates.
function List({ items }) {
function Row({ item }) { return <li>{item.name}</li>; } // new component type each render
return items.map(i => <Row key={i.id} item={i} />);
}
Every render creates a new Row type, so React unmounts and remounts all rows: state and focus are lost, and it's slow. Define components at module level.
useState(props.value) only reads the initial value and then drifts. Either use the prop directly, name it initialValue, or reset with a key.
state.items.push(x); setItems(state.items) doesn't re-render reliably and breaks memoization. Create new objects.
Index keys in reorderable lists, or key={Math.random()}, cause wrong state and remounts.
A 1,000-line component with fifteen useStates, or one context holding everything, re-renders too much and is hard to change. Split by responsibility, colocate state with where it's used, and use reducers for related state.
Wrapping everything in useMemo/useCallback/memo adds noise and cost. Ignoring obvious hot paths (a 5,000-row table re-rendering on every keystroke) is the opposite problem. Profile first. With the React Compiler, manual memoization is largely unnecessary.
Subscribing, setting timers, mutating globals, or calling setState unconditionally during render. Strict Mode exists to surface these.
useEffect(async () => …) (an async function returns a promise, not a cleanup).dangerouslySetInnerHTML with unsanitized input.children, slots, compound components).exhaustive-deps instead of fixing the closure.Spotted a mistake or a rights concern? Report an issue