Course contentsShow
← React
Lesson 655 of 2,39617. Common useEffect MistakesFree lesson

Recognizing the Pattern in the Wild

Spotting code where useEffect dependencies and state setters reveal derived state that should be computed inline.

Recognizing the Pattern in the Wild

You'll learn to spot the telltale signs of derived state being unnecessarily placed in effects instead of computed inline.

Now that you understand why deriving state in effects is wrong, let's train your eye to catch this antipattern when reading real codebases.

The Red Flags

Look for these warning signs:

1. State that's just a transformation of props or other state:

// 🚨 Red flag: state depends entirely on props
useEffect(() => {
  setFilteredItems(items.filter(item => item.active));
}, [items]);

2. Dependencies that perfectly match the state setter's inputs: If every value in your dependency array is used to calculate the new state, you're probably deriving.

3. Effects that run immediately on mount with no async work: No fetch, no timers, no subscriptions—just synchronous calculation? That's derived state.

4. Variables named like transformations: filteredX, sortedY, computedZ, displayName—these names scream "I should be calculated during render."

The Pattern Recognition Checklist

When reviewing code, ask:

  • Does this effect do anything besides setState?
  • Could this value be calculated from existing data?
  • Is there any reason this needs to wait until after render?

If the answers are "no," "yes," and "no"—you've found derived state hiding in an effect.

Key Takeaway: The antipattern reveals itself when you see effects that only transform props/state into new state with no side effects—those values should be computed during render or memoized with useMemo instead.