react-component / react-component/field-form
Field with dependencies is not rerendered when dependent field finishes validation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 286
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 1
Description
In the following example, editing the username field will update the dependant field value but not the errors.
<Form>
<Field name="username" rules=[{ required: true }]}>
<Input />
</Field>
<Field dependencies={["username"]}>
{(controls, meta, context) => (
<div>
<div>Value: {context.getFieldValue("username") || "null"}</div>
<div>Errors: {context.getFieldError("username").join(", ")}</div>
</div>
)}
</Field>
<Form>
Reproduction: https://codesandbox.io/s/antd-reproduction-template-forked-5ux1r?file=/index.js
The same behavior can only be achieved via a shouldUpdate={true} as using a custom shouldUpdate where we only compare the previous and current values of the username field would not work as value would be the same when info.type="validationFinish" triggers. Using shouldUpdate={true} is undesirable given the performance implications. Another option would be to add further information the 3rd parameter passed to shouldUpdate so the user can better choose when to rerender.
The above is the simplified use case. The real use case is to extract the form's item errors and render them via a custom component.
Related to https://github.com/ant-design/ant-design/issues/26888.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox reproduction in index.js, then trace how Form and Field dependencies handle validation finishing. Done means a dependent field rerenders to show updated errors without requiring shouldUpdate={true}, while avoiding the broad performance cost described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100