Skip to content
React·Intermediate·Coding·1 min read

Why is copying props into state with an effect often wrong?

Short interview answer

It creates two sources of truth and an extra render with temporarily stale derived state. Compute inexpensive values during render, memoize only costly pure computation when measured, or deliberately reset state through identity when the product requires it.

Example

JSX
// Anti-pattern: effect mirrors a prop into stateuseEffect(() => setFullName(`${first} ${last}`), [first, last]);
// Just derive during render:const fullName = `${first} ${last}`;

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to React effects

Related questions