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

17
Vistas
Add elements to reducer state using redux toolkit

I'm using React 18 with Vite, Redux Toolkit 2.1.0.

What I'm trying to achieve is to add all events fetched from a MongoDB database to the state of my reducer.

This is part of my calendar segment.

 export const calendarSlice = createSlice({
 name: 'calendar',
 initialState: {
 loadingEvents: false,
 events: [],
 activeEvent: null
 },
 reducers: {
 onLoadEvents: (state, { payload = [] }) => {
 state.loadingEvents = true;
 payload.forEach(event => {
 const exists = state.events.some(dbEvent => dbEvent.id === event.id);
 if (!exists) {
 state.events.push(event);
 }
 });
 }
 }

});

If I do a console.log with the payload I can see all the events from the database, however the push command does not add the events to state.events .

I did a search on previous posts here on the website but still couldn't find a solution to my problem.

over 2 years ago · Carlos Garzón Colorado
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