Skip to main content
⚑ OpenDevDocs
React
frontendreactTroubleshootingIntermediate

Common React Mistakes and Anti-Patterns

Avoiding frequent React mistakes: mutating state directly, infinite useEffect loops, missing keys, stale closures, and over-using Context.

Verified: 2026-09-30
Tested on:react 19.x
Platforms:
web
#react#anti-patterns#mistakes#troubleshooting#debugging

Common React Mistakes and Anti-Patterns

A diagnostic checklist of the most common mistakes made in React codebases.


1. Mutating State Directly

// ❌ WRONG: Mutating existing array
items.push("new item");
setItems(items); // React thinks reference didn't change!

// βœ… CORRECT: Return a new array reference
setItems([...items, "new item"]);

2. Infinite useEffect Render Loops

// ❌ WRONG: Updating state that is in the dependency array
const [data, setData] = useState([]);
useEffect(() => {
  fetchData().then(res => setData(res)); // Triggers re-render -> triggers effect -> infinite loop!
}, [data]);

// βœ… CORRECT: Empty array or specific ID dependency
useEffect(() => {
  fetchData().then(res => setData(res));
}, []); // Runs once on mount

3. Stale Closures in Asynchronous Code

// ❌ Bug: `count` is captured at the time setInterval was initialized (always 0)
useEffect(() => {
  const id = setInterval(() => {
    setCount(count + 1);
  }, 1000);
  return () => clearInterval(id);
}, []);

// βœ… Fix: Use the functional updater form
useEffect(() => {
  const id = setInterval(() => {
    setCount(prev => prev + 1); // Always gets latest value
  }, 1000);
  return () => clearInterval(id);
}, []);

4. Derived State Stored in State

// ❌ Anti-pattern: Redundant state sync
const [users, setUsers] = useState([]);
const [activeUsers, setActiveUsers] = useState([]);

// βœ… Fix: Derive directly during render!
const activeUsers = users.filter(u => u.isActive);

On this page