【问题标题】:How to store or access payload data in Redux如何在 Redux 中存储或访问有效负载数据
【发布时间】:2021-07-08 07:45:34
【问题描述】:

我是 redux 的新手,但我有一个问题让我很困惑,所以假设我们有一个这样的 Reducer

initState = {
  loginStatus: false,
};
const LoginAction = (state = initState, action) => {
  if (action.type == changeLogin) {
    return { loginStatus: !state.loginStatus };
  } else if (action.type == getDefault) {
    return { loginStatus: false };
  }
  return state;
};
export default LoginAction;

访问这个reducer数据很容易,得到loginStatus,只需state.LoginStatus通过使用useSelector钩子但是如果我有这样的动作

export const GetUserInfo = (user, password) => ({
  type: actionList.GET_USER_INFO,
  data: { user, password },
});

如何访问或更改这些有效载荷(user, password) 中的数据?? 非常感谢您的帮助

【问题讨论】:

  • action.data.useraction.data.password?您是否在问如何访问减速器中的操作属性?你能澄清你的问题或问题是什么吗?
  • 我的意思是访问主文件中的数据,例如,主文件作为登录屏幕,login.js我使用useSelector访问Reducer项,但我不知道如何使用action 文件中的项目
  • React UI 不使用 action 对象,它将它们分派到 redux store。
  • 那么我如何才能访问这些项目,我是 redux 的新手,所以这个问题可能有点愚蠢,但我真的不知道该怎么做,官方的 redux 文档让我更加困惑: (
  • 您需要在 reducer 中处理该操作,更新一些状态,然后在 UI 中选择该状态,就像您在 state.loginStatus 中所做的一样。

标签: reactjs react-native redux redux-saga


【解决方案1】:

我附上了可能有助于您构建应用的 redux 官方文档。

https://redux.js.org/introduction/getting-started

【讨论】:

    猜你喜欢
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 2023-02-11
    • 2017-05-12
    • 1970-01-01
    • 2017-10-12
    相关资源
    最近更新 更多