InterviewHubPRO
Section Overview
Q334

Question 334 of 445

Part 10: Modern React 18, React 19 & Next.js Patterns (317 - 353)

75%
React & Modern Frontend (445 Qs)•Part 10: Modern React 18, React 19 & Next.js Patterns (317 - 353)

Why is normalized state important for performance?

  1. O(1) lookups by ID instead of scanning/find()-ing through an array every time a component needs one item.
  2. Updates are localized: changing one entity only replaces that entity's entry in the entities map, so components subscribed to other entities don't see a changed reference and don't re-render.
  3. No duplicate data to keep in sync: with nested/duplicated data, updating a single author's name might require updating it in every post that embeds it; normalized state updates it once.
  4. Cheaper equality checks: since each entity is a small, independent object, memoized selectors (createSelector) and useSelector reference comparisons stay cheap and precise instead of comparing/deep-cloning large nested trees.
  5. Simpler reducers: adding/removing/updating one item is a straightforward map operation, rather than mapping/filtering over deeply nested arrays.

Practical Code Example

javascript
// Normalized State: Avoids duplicate nested data and O(N) updates:
// Normalized schema:
const state = {
  users: {
    byId: { 'u1': { id: 'u1', name: 'Alex' } },
    allIds: ['u1']
  }
};