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

217
Vistas
Cant access state inside reducer

I have createslice and reducer like this. I want to print my state inside reducer cause my dispatch is not working correctly but when i am trying to printing the state.event i am getting this.

[Proxy]
0: Proxy {}
length: 1
__proto__: Array(0)

export const eventSlice = createSlice({
      name: 'event',
      initialState: {
        event: [],
        favouriteEvents: [],
        isFetching: false,
        isSuccess: false,
        isError: false,
        errorMessage: '',
      },
    
      reducers: {
        alterFavourite: (state, action) => {
       // item = state.event.filter((item) => {
       //   item.pk == parseInt(pk)
       // item.is_liked = !is_liked;
       // })
    
        console.log(state.event)
      },
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use current function:

Immer exposes a named export current that creates a copy of the current state of the draft. This can be very useful for debugging purposes (as those objects won't be Proxy objects and not be logged as such). Also, references to current can be safely leaked from a produce function. Put differently, current provides a snapshot of the current state of a draft.

RTK uses immer underly and re-exports these functions. The state in the reducer is a draft object, it is some kind of wrapper or proxy of the JavaScript plain object.

You can do this:

import { configureStore, createSlice, current } from '@reduxjs/toolkit';

export const eventSlice = createSlice({
  name: 'event',
  initialState: {
    event: [],
    favouriteEvents: [],
    isFetching: false,
    isSuccess: false,
    isError: false,
    errorMessage: '',
  },

  reducers: {
    alterFavourite: (state, action) => {
      // console.log(state.event);
      console.log('current state.event: ', current(state.event));
    },
  },
});

const store = configureStore({
  reducer: {
    event: eventSlice.reducer,
  },
});
store.dispatch(eventSlice.actions.alterFavourite(null));

Output:

current state.event:  []

package version: "@reduxjs/toolkit": "^1.6.1"

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