Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
React decides whether to re-render by comparing references; mutating keeps the same reference, so the UI may not update, and other code holding the old value sees unexpected changes.
When you call a setter, React compares the new value with the old one using Object.is. If you push into the same array and pass it back, the reference is unchanged, so React may skip the update. Mutation also breaks features that rely on old snapshots, such as memoized children and comparisons in effects. Instead, create new values: [...items, newItem], items.filter(...), items.map(...) or { ...user, name }. For deeply nested data, a helper like Immer can produce immutable updates with simpler code.