Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Normalizing state in Redux

I tried to google some real-world examples of using normalized state in redux, but nothing useful was found, so, I'm here to try clarify some moments about splitting normalized state during app lifecycle.

In my app I have
~ users and posts entities
~ search page where I can search users by name and check their posts

For search page I have searchReducer.
In usual way, for searching users, I'll just send request (/users?search='eugene') and then save found users in my searchReducer:

// searchReducer

const foundUsers = [
  {
    id: 1,
    name: 'Eugene',
    posts: [
      {
        id: 24,
        title: 'Hello',
        text: 'Lorem ipsum',
      },
      {
        id: 26,
        title: 'Goodbye',
        text: 'Ipsum lorem',
      }
    ],
  },
  {
    id: 2,
    name: 'Eugene',
    posts: [],
  }
]

How can I change this to normalized state?
If I understand everything right, I have to split this data into 2 global reducers, 'users' and 'posts?

// usersReducer
const users = {
  byId: {
    1: {
      id : 1,
      name: 'Eugene',
      posts: [24, 26],
    },
    2: {
      id : 2,
      name: 'Eugene',
      posts: [],
    },
  },
  allIds : [1, 2],
}

// postsReducer
const posts = {
  byId: {
    24: {
      id: 24,
      title: 'Hello',
      text: 'Lorem ipsum',
      userId: 1,
    },
    26: {
      id: 26,
      title: 'Goodbye',
      text: 'Ipsum lorem',
      userId: 1,
    },
  },
  allIds: [24, 26],
}

And in searchReducer just create variable with usersIds:

const foundUsers = [1,2];

Is it correct way to organize normalized state?
It looks nice but how I understand, if I'll do a lot of searches (on /search page), I can get a huge amount of posts in postReducer that will lead to bad performance.
Of course, I can clear posts before doing new search, but in theory, some posts can be also be needed for other reducer in app, so here I can't find some good way of doing something like garbage collector.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!