gpt4 book ai didi

redux-form - 从父组件获取 redux-form 有效属性

转载 作者:行者123 更新时间:2023-12-01 12:13:57 24 4
gpt4 key购买 nike

我在“reduxForm”组件之外有我的提交按钮
如果表单无效,如何禁用按钮?

<MainComponent><MyForm/><MyButton disabled={???}/></MainComponent>

最佳答案

使用 isValidisInvalid选择器。

isValid(formName:String) returns (state) => valid:boolean Returns true if the form is valid, i.e. has no sync, async, or submission errors. The opposite of isInvalid.

isInvalid(formName:String) returns (state) => invalid:boolean Returns true if the form is invalid, i.e. has sync, async, or submission errors. The opposite of isValid.


import {
isValid,
isInvalid
} from 'redux-form'

MyComponent = connect(
state => ({
valid: isValid('myForm')(state),
invalid: isInvalid('myForm')(state)
})
)(MyComponent)

并在您的渲染功能中使用它来禁用按钮:
<MainComponent><MyForm/><MyButton disabled={this.props.invalid}/></MainComponent>

关于redux-form - 从父组件获取 redux-form 有效属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49634786/

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