【问题标题】:where to access redux store from parent component从父组件访问 redux 存储的位置
【发布时间】:2019-03-21 10:38:23
【问题描述】:

我有一个显示表格组件的仪表板组件。在仪表板组件上,我正在通过 componentdidmount 中的异步等待调用加载带有帐户信息的 redux 存储,我想使用来自该调用的帐户信息来过滤来自子表组件的数据。我应该在哪里尝试从子组件访问 redux 存储?目前我在componentdidmount中有它并且值为空。当我在两个componentdidmount中放入console.logs时,似乎在子componentdidmount之后调用了仪表板componentdidmount。非常感谢任何帮助。

【问题讨论】:

  • 请发布您的代码
  • 你可以在 child 中使用 componentDidUpdate 来检查 prop 是否改变并采取行动
  • 使用重新选择进行数据聚合/操作

标签: reactjs react-redux


【解决方案1】:

可以在componentWillReceiveProps中访问redux store

componentWillReceiveProps(nextProps) {
   console.log(nextProps);
}

由于 React 16.3+ 引入了静态 getDerivedStateFromProps,这是一个返回状态的静态方法 欲了解更多信息,请访问this link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 2013-09-07
    • 2016-12-25
    • 2016-04-26
    • 2023-02-11
    • 1970-01-01
    • 2019-02-11
    相关资源
    最近更新 更多