jaredpalmer / jaredpalmer/formik
Why do I have to specify a name again when using useField's onChange function?
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 34.3k
- Forks
- 2.8k
- PR merge metrics
- No merged PRs in 30d
Description
Bug report
Current Behavior
When using the useField() hook, like so:
const [field, meta, helpers] = useField<any>(name);
Then when I want to call field.onChange(), I have to do it like this:
field.onChange(name)(value)
While this doesn't work:
field.onChange(value)
As you can see I have to specify the name once again when calling the onChange(). This seems redundant since
a ) The useField hook is already provided the name
b ) The hook only exposes you to a single field
Expected behavior
I'd expect to be able to call field.onChange without needing to provide the name of the field again.
Suggested solution(s)
Store the field name in the useField hook (I'm guessing that this is already there), then infer the field name in the onChange function (and any other functions that require you to pass a name).
| Software | Version(s) |
|---|---|
| Formik | 2.4.3 |
| React | 18.2.0 |
| TypeScript | 5.1.3 |
| Browser | Chrome |
| npm/Yarn | Yarn |
| Operating System | Windows |
Contributor guide
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 at the useField() hook and trace how field.onChange is created and invoked. Confirm the current name-and-value behavior, then check the existing useField coverage if available; done means a field obtained from useField can pass its value directly to onChange without repeating the field name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100