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

115
Vistas
How should i use createEntityAdapter to use selectors from within slice reducers?

At the moment, im defining all my adapters in an adapters file and exporting them from there. Within my slice, i export a selectors object within which i include the selectors generated by my entityAdapter. Since my entityState is nested within the slice state, i've defined the selectors like so:

const entitySelectors = myAdapter.getSelectors<RootState>((state) => state.sliceState.entities)

I want to use these selectors in the reducers (which have access to slice state) of the same slice they are exported from so that i'm not writing logic that the adapter already has for me. Is there an elegant way to do this without having to define two versions of the same selectors (one for RootState, and one for SliceState)?

I could just have:

const sliceStateSelectors = myAdapter.getSelectors<SliceState>((state) => state.entities);
const rootStateSelectors = myAdapter.getSelectors<RootState>((state) => state.sliceState.entities);

export const selectors = {
...rootStateSelectors,
// other selectors
}

and use sliceState selectors in my reducers, but it doesn't seem desirable from a clarity/repetition standpoint.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

A Redux selector does typically expect the entire Redux root state object as an argument, but a slice is only a part of that state. So, yes, if you want to use selectors inside of reducers, you'd need to create the alternate versions that can accept just the slice state.

That said: I honestly would recommend against trying to use selectors inside of a slice's reducers. There's not really any benefit here. It's easy enough to do state.entities[someId] instead of selectById(), etc, and the slice's reducer logic is in control of how those items are being stored anyway.

about 4 years ago · Juan Pablo Isaza Denunciar
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