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

28
Views
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
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!