我正在尝试使用我的redux-form使用ant.design react组件,到目前为止它是这样的:
@H_502_2@import { Form,Input } from 'antd';
import { Field,reduxForm } from 'redux-form/immutable';
const FormItem = Form.Item;
.....
<FormItem>
<Field
component={Input}
placeholder="First Name"
name="name"
/>
</FormItem>
似乎antd表单输入不支持name属性,它们忽略并阻止将其传递下去.
redux-form需要name属性才能工作.
有没有人成功让这两个人一起工作?谢谢.
解决方法
除了Maxim的回答之外,我还必须将redux-form props.input comp传递给antd Input组件.
@H_502_2@const NewInput = ({
label,labelCol,wrapperCol,help,extra,validateStatus,hasFeedback = true,colon,...rest
}) => {
return (<FormItem
label={label}
wrapperCol={wrapperCol}
labelCol={labelCol}
help={help}
hasFeedback={hasFeedback}
extra={extra}
validateStatus={validateStatus}
colon={colon}
>
<Input {...rest.input} />
</FormItem>);
};