【问题标题】:Access Redux Store from Redux Form从 Redux 表单访问 Redux Store
【发布时间】:2019-08-15 16:16:29
【问题描述】:

我无法从我的 redux-form 访问 redux 状态。

我查看了How to access the redux store within the redux form,但这些解决方案都不起作用。

class PersonalInfo extends Component {


    renderContent() {
        console.log(this.state)
......
}

function mapStateToProps(state) {

    return {
      state
    };
  }

export default reduxForm({
    form: "AccountOverview",
})(connect(mapStateToProps)(PersonalInfo))

当我使用 console.log(this.state) 或 state 时它会导致 null

【问题讨论】:

标签: react-redux redux-form


【解决方案1】:

mapStateToProps 会将 redux 状态映射到组件的属性,因此您可以通过 props 属性访问它。其实顾名思义,redux 状态映射到组件props

这应该可行:

console.log(this.props.state)

检查沙盒here

【讨论】:

    猜你喜欢
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    相关资源
    最近更新 更多