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

138
Vistas
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
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