Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JorensM opened this issue Jan 14, 2024 · 0 comments

Comments

@JorensM
Copy link

JorensM commented Jan 14, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant