小编Jon*_*Jon的帖子

如何在 Redux 工具包中获取 State()

我有以下切片和函数。如何获取存储在初始状态中的值?

const example = createSlice({
  name: "example",
  initialState: {
   firstName: hello,
   lastName: world
  },
  reducers: {}
 })

export const create = (id) => {
  return async (dispatch) => {
      const currentState = getState()
      console.log(currentState) 
  };
};
Run Code Online (Sandbox Code Playgroud)

我是否必须使用 useSelector 并将值再次传递给函数?理想情况下希望直接从已保存的状态获取数据

reactjs redux react-redux redux-toolkit

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

react-redux ×1

reactjs ×1

redux ×1

redux-toolkit ×1