final-form / final-form/react-final-form
[API improvement proposition] validate fat arrow function, use latest ref pattern
- Dominant language
- JavaScript
- Stars
- 7.4k
- Forks
- 497
- PR merge metrics
- No merged PRs in 30d
Description
Hey,
### Are you submitting a **bug report** or a **feature request**?
Feature request
### What is the current behavior?
Currently, when passing an inline function for the `validate` prop, we also need to change another prop if we want the change to be taken into account. I know about it, but teammates have been bitten by this.
Docs: https://final-form.org/docs/react-final-form/types/FieldProps > validate
### What is the expected behavior?
Have you considered using the latest ref pattern? https://epicreact.dev/the-latest-ref-pattern-in-react/
The idea would be to store a reference to the `validate` function in `useLayoutEffect` so we can later access it in `useEffect`, but without including it in the dependency array.
I have not dived into the code yet so maybe this solution wouldn't apply, but I wanted to know your stance on this before creating a PR.
This would drastically improve developer experience, especially for folks new to react-final-form.
### Other information
/
Thanks in advance!
Contributor guide
Research direction
Start with the FieldProps documentation, especially the validate prop behavior, then locate the React field implementation that handles validate changes. Confirm how an inline validation function is currently observed and define done as making its changes take effect without requiring another prop change. The issue includes no file or test name, so code discovery and design validation are required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100