"this.props.forms.getFieldValue" can help me to reduce the unnecessary controlled code. But it cannot be applied to custom input compoenent.
I make a simple custom select compoenent——none styles be changed,just some code about data fetch and handle in "componentDidMount".
But it seems cannot be reconized by "this.props.forms.getFieldValue". So I had to make it to be a controlled component and add some simple , tedious code .
class CustomSelect extends React.Component {
constructor(props){...}
getFieldValue() {
return this.state.value
}
setFieldName(name) {
this.setState({name: name})
}
getFieldName(name) {
return this.state.name
}
render() {
<Select
onChange={value=>this.setState(value:value)}
>... </Select>
}
}
the custome component will be accessed by "this.props.forms.getFieldValue" just like any other antd Input component via the interface provided by antd.
If there's any problem in the issue , please let me know.
regards.
https://ant.design/components/form/#components-form-demo-customized-form-controls
Most helpful comment
https://ant.design/components/form/#components-form-demo-customized-form-controls