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

204
Views
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 answers
Answer question

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 Report
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!