Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda