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

Suggested pattern for programmatically updating other fields? #41

Open
gwhobbs opened this issue Oct 6, 2021 · 0 comments
Open

Suggested pattern for programmatically updating other fields? #41

gwhobbs opened this issue Oct 6, 2021 · 0 comments

Comments

@gwhobbs
Copy link

gwhobbs commented Oct 6, 2021

Thanks for your work on reacto-form!

I currently have a scenario where one field is dependent on another—something roughly along the lines of a country and state/territory select, where changing the country should clear any previously selected state/territory value. The solution I came up with is:

  1. Create a formRef with useRef() pointing to the latest object returned by useReactoForm()
  2. Call setTimeout(countryDidChange, delay) whenever the country field onChange() event has fired
  3. countryDidChange does something like formRef.current.getInputProps('state').onChange(null);

This works, but seems inelegant. I was wondering if this is something others had come across—and if so, is there a recommended pattern for handling these cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant