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

16
Views
Agregue elementos al estado reductor usando el kit de herramientas redux

Estoy usando React 18 con Vite, Redux Toolkit 2.1.0.

Lo que intento lograr es agregar todos los eventos obtenidos de una base de datos MongoDB al estado de mi reductor.

Esto es parte de mi segmento de calendario.

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);
                }
            });
        }
    }

});

Si hago una console.logcon la carga útil, puedo ver todos los eventos de la base de datos, sin embargo, pushel comando no agrega los eventos a state.events.

Hice una búsqueda en publicaciones anteriores aquí en el sitio web pero aún no pude encontrar una solución a mi problema.

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