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

134
Views
Cannot push to array state in Redux Tookit

I'm using Redux Toolkit but I can't seem to find a way to add a new value of an array of objects.

Here's my reducer:

import { createSlice, current } from "@reduxjs/toolkit"

const initialState = {
  positions: []
}

export const userSlice = createSlice({
  name: "user",
  initialState,
  reducers: {
    setPositionsAction(state, { payload }) {
      state.positions = payload
    },
    addPositionAction(state, { payload }) {
      state.positions.push(payload)
    }
  }
})

export const {
  setPositionsAction,
  addPositionAction
} = userSlice.actions

export default userSlice.reducer

I'm dispatching the request after a successful axios request

dispatch(addPositionAction(response))

But the state gets deleted and only contains the new value I just added, removing completely all the data that was containing before.

What am I missing?

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