I am trying to access my initial state in redux and I am being returned a proxy object. How can I access what is in my state?
It should be returning some large 2D array for a grid. It works fine with small things like booleans but not with this.
That large array returns perfectly when I directly log it on the console but I get this when I set that array to my initial state and log it from there.
Proxy {0: {…}}
[[Handler]]: null
[[Target]]: null
[[IsRevoked]]: true
This is the initialState
:
const initialState = {
grid: initialGrid,
isMousePressed: false,
};
The grid shows up in the redux state perfectly fine but I can't log it on the console.
I found out from this page that I need to access the value from target
so
I tried console.log(state.grid.target)
and everything else on the list but it still does not work.
Does anyone know what to do?
I am trying to access my initial state in redux and I am being returned a proxy object. How can I access what is in my state?
It should be returning some large 2D array for a grid. It works fine with small things like booleans but not with this.
That large array returns perfectly when I directly log it on the console but I get this when I set that array to my initial state and log it from there.
Proxy {0: {…}}
[[Handler]]: null
[[Target]]: null
[[IsRevoked]]: true
This is the initialState
:
const initialState = {
grid: initialGrid,
isMousePressed: false,
};
The grid shows up in the redux state perfectly fine but I can't log it on the console.
I found out from this page that I need to access the value from target
so
I tried console.log(state.grid.target)
and everything else on the list but it still does not work.
Does anyone know what to do?
Share Improve this question asked Dec 25, 2020 at 14:22 Devesh KumarDevesh Kumar 1861 gold badge4 silver badges19 bronze badges 1-
what happens when you try
console.info(state.grid.target)
– Sinan Yaman Commented Dec 25, 2020 at 14:30
1 Answer
Reset to default 9I'm assuming you're using our official Redux Toolkit package and its createSlice
API.
createSlice
uses Immer internally, which wraps your data in a Proxy so it can track attempted updates.
You need to use the current
utility from Immer to unwrap the data if you want to log it, as re-exported by RTK:
console.log(current(state))
See https://redux-toolkit.js/api/other-exports#current