Debounce async validation function calls when mode is `onChange`

See original GitHub issue

Hi guys — First of all, thumbs up for this super cool library 👍

I recently noticed that when the validation mode in onChange and I have a field which performs async validation, the function is called every time the field changes, which is kind of wasteful. It would be nice to have a debounce functionality so the async function isn’t called every time. The usual scenario si when a user is typing on a field and I only want to validate when the typing is done, I don’t care about validating on each keystroke. This behavior is slightly better IMHO than the onBlur alternative, because the user could get a feedback when the focus is still on the field that is being filled in. And the feedback shouldn’t “harass” the user.

Please see this example for reference (open the dev console and type in the Username field). https://codesandbox.io/s/react-hook-form-async-field-validation-50cyw

Is there a way I can achieve debouncing already? Am I missing something? Thanks for your attention.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:29 (8 by maintainers)

github_iconTop GitHub Comments

25reactions
durchanekcommented, Apr 30, 2020

For anyone looking for an easy solution, I solved this with awesome-debounce-promise

validate: debouncePromise(async (value) => {
  return await validatePhoneNumber(value) || 'Phone number is invalid';
}, 500),
4reactions
trumbittacommented, Apr 23, 2021

For anyone looking for an easy solution, I solved this with awesome-debounce-promise

validate: debouncePromise(async (value) => {
  return await validatePhoneNumber(value) || 'Phone number is invalid';
}, 500),

Awesome and simple. Fantastic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use debounce on input change with React-hook-form ...
react-hook-form has the onChange mode which will automatically trigger validation when there is a change in the input fields.
Read more >
How to debounce async formik/yup validation, that it will ...
I want to validate user input asynchronously. For example, to check if email already exists, and perform validation while the user typing. To ......
Read more >
Data Grid - Editing - MUI X
With debounce. By default, each call to apiRef.current. · With auto-stop. An edit component has "auto-stop" behavior when it stops edit mode as...
Read more >
Backbone.js
The validate method receives the model attributes as well as any options passed to set or save, if validate returns an error, save...
Read more >
Debouncing React controlled components - DevDojo
Every time I had to debounce, it's usually an uncontrolled component. ... A function to execute the callback */ function debounce(callback, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found