gpt4 book ai didi

reactjs - 如何使用 this.props.change 更改 redux 形式的深层字段

转载 作者:行者123 更新时间:2023-12-03 13:37:40 26 4
gpt4 key购买 nike

我想用 redux-form V6 中的 this.props.change 更改 redux-form 中的深层字段。

这是我的mapStateToProps:

function mapStateToProps(state) {
const {recipient_type, filters} =
formValueSelector('form_wizard')(
state, 'filters.recipient_type' ,'filters');

return {
recipient_type,
filters
}
}

这是我的componentDidMount(我想以编程方式更改深场)

componentDidMount() {
if (!this.props.recipient_type) {
this.props.change("filters.recipient_type}", someThing);
}
}

this.props.recipient_type 的结果未定义。

问题:

如何在 redux-form 中使用 this.props.change() 更改深度字段?

谢谢

最佳答案

终于找到答案了

如果你想访问 redux-form 中的深层字段,你必须使用 formValueSelector 中的父键来获取它:

function mapStateToProps(state) {
const {filters} =
formValueSelector('form_wizard')(
state, 'filters.recipient_type' );
return {
recipient_type : filters,
}
}

如果您需要获取父字段:

function mapStateToProps(state) {
const {filters} =
formValueSelector('form_wizard')(
state, 'filters' );
return {
recipient_type : filters.recipient_type,
}
}

关于reactjs - 如何使用 this.props.change 更改 redux 形式的深层字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52145073/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com