最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Redux returning a proxy object instead of the state - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 9

I'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

发布评论

评论列表(0)

  1. 暂无评论