Skip to content

Suggested pattern for programmatically updating other fields? #41

@gwhobbs

Description

@gwhobbs

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions