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

Seeking a way to watch for changes via setValue, since <Form onChange/> won't work #3698

Closed
mikestopcontinues opened this issue Dec 15, 2020 · 3 comments · Fixed by #3741
Closed
Labels
feature request request a feature to be added

Comments

@mikestopcontinues
Copy link

Is your feature request related to a problem? Please describe.
My current app has a number of forms with duplicated logic, so I have a <CustomForm> element I use to handle the logic. One of the most important parts is that CustomForm handles watching for changes, then sends them to an iframe to make live updates.

This works great for user-initiated changes to form fields, but it fails when I need to use setValue, naturally because it doesn't trigger a change event. One example is a rich text field (using slate). Another is a drag-and-drop avatar uploader.

So I'm seeking some way to watch for all changes to the form data. watch() isn't a great solution because I need to know what field just changed, not just that the entire object changed. I would prefer not to do a deep equal for every character a user types, you know?

Describe the solution you'd like

Some ideas:

  • Maybe setValue triggers a synthetic change event.
  • Maybe watch() receives a callback function cb(name, value, ref).

Additional context
I've looked through the issues and discussion. It seems like this is a fairly common pain point. That said, I can definitely imagine I'm just missing an easy way to do this as is.

@bluebill1049 bluebill1049 added feature request request a feature to be added waiting-up-vote Waiting for votes from the community. labels Dec 16, 2020
@bluebill1049 bluebill1049 added this to Pending Feature Requests in React Hook Form Dec 16, 2020
@bluebill1049
Copy link
Member

Thanks for the feature request, putting it into the project board.

@bluebill1049 bluebill1049 moved this from Pending Feature Requests to API proposal / RFC in React Hook Form Dec 29, 2020
@bluebill1049
Copy link
Member

V7 watch will support this.

watch((d) => {
  console.log('changed here', d)
})

@bluebill1049
Copy link
Member

feel free to drop a comment here: #3714

@bluebill1049 bluebill1049 moved this from API proposal / RFC to In progress in React Hook Form Jan 3, 2021
@bluebill1049 bluebill1049 mentioned this issue Jan 17, 2021
17 tasks
@bluebill1049 bluebill1049 moved this from In progress to Done in React Hook Form Mar 4, 2021
@bluebill1049 bluebill1049 removed the waiting-up-vote Waiting for votes from the community. label Mar 13, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature request request a feature to be added
Projects
Development

Successfully merging a pull request may close this issue.

2 participants