Higher-order API for getFieldDecorator
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
What problem does this feature solve?
The current API for getFieldDecorator leads to multiple problems for me. The biggest issue is that it interferes with flow type checking, since you are forced to construct react components for which some props are magically added afterwards. For example, SomeInputComponent
might be a react component which always expects a value
prop. Even though, getFieldDecorator
will ensure that this prop is added, flow (and TypeScript probably too?) will complain that the prop was not provided. If a “dummy prop” is provided, antd will complain about that.
<FormItem label="Label">
{getFieldDecorator("name")(<SomeInputComponent />)} // <-- strictly speaking, a prop is missing here
</FormItem>
What does the proposed API look like?
In my opinion the following API would yield multiple benefits:
<FormItem label="Label">
{getFieldDecorator("name")((value, onChange) => <SomeInputComponent value={value} onChange={onChange} />)}
</FormItem>
Since props are passed via a normal mechanism (function parameters) and not through some “magic way”, you would get:
- Better typechecking
- You would avoid options, such as
valuePropName
, since you could easily map things in your higher-order function yourself (e.g.,(value, onChange) => <Checkbox checked={value} />
). - The API could also work for stateless components (not too sure about that, though?), which is not possible at the moment.
If you are concerned about conciseness, you could always write something like {getFieldDecorator("name")(props => <SomeInputComponent {...props} />)}
.
What do you think? Is this doable? Or are there strong reasons not to follow this approach?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:12 (2 by maintainers)
Top GitHub Comments
In Form, we want to simplify developer code since it cost too much duplicate code if use render component. In addition, we have plan for optimizing performance with Form. This will make hard to do so.
We may not accept this feature requirement currently.
is this problem solved? can anyone tell me how to solve it?