Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

29
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda