Redux 返回代理对象而不是状态

Redux returning a proxy object instead of the state

我正在尝试访问我在 redux 中的初始状态,我被返回了一个代理对象。我怎样才能访问我所在州的内容?

它应该为网格返回一些大型二维数组。它适用于像布尔值这样的小东西,但不适用于这个。

那个大数组 returns 当我直接在控制台上登录时非常完美,但是当我将该数组设置为我的初始状态并从那里登录时我得到了这个。

Proxy {0: {…}}
[[Handler]]: null
[[Target]]: null
[[IsRevoked]]: true

这是initialState:

const initialState = {
  grid: initialGrid,
  isMousePressed: false,
};

网格在 redux 状态下显示得非常好,但我无法在控制台上记录它。 我从 中发现我需要访问 target 中的值,所以 我尝试了 console.log(state.grid.target) 和列表中的所有其他内容,但仍然无效。

有人知道怎么办吗?

我假设您正在使用 our official Redux Toolkit package 及其 createSlice API。

createSlice 在内部使用 Immer,它将您的数据包装在代理中,以便它可以跟踪尝试的更新。

如果要记录数据,您需要使用 Immer 的 current 实用程序来解包数据,如 RTK 重新导出的那样:

console.log(current(state))

https://redux-toolkit.js.org/api/other-exports#current