https://github.com/ant-design/ant-design/issues/11259Go to Github

FundedView inHigher-order API for getFieldDecorator#11259

philippottocreated the issue 3 months ago

  • 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:

  1. Better typechecking
  2. 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} />).
  3. 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?

<!-- generated by ant-design-issue-helper. DO NOT REMOVE -->

Logs

  1. loadbalance-sudachi-kunfunded $256about 1 month ago
  2. 0maxxam0funded $23 months ago

Total Fund

$258

You will get $180.6 when resolving this issue

Funded by

2

Work status

No one is working