jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.71k stars 2.77k forks source link

Why do I have to specify a name again when using useField's onChange function? #3941

Open JorensM opened 5 months ago

JorensM commented 5 months ago

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