react-hook-form / documentation

📋 Official documentation
http://react-hook-form.com
MIT License
723 stars 1.03k forks source link

Document watch callback type parameter #1040

Open vladev opened 8 months ago

vladev commented 8 months ago

Is your feature request related to a problem? Please describe. Using the watch API in useEffect like so:

useEffect(() => {
  watch((data, {name, type}) => {
    console.log(data, name, type)
  })
})

It seems type indicates who initiated the update, because a user change results in type: 'change', while a setValue call results in type: undefined. I'm actually using it avoid endless watch calls as I call setValue inside watch, which results in a new watch callback call. I'd like to ask for documentation of this type field.

Describe the solution you'd like Document the possible options for the type attribute in watch callback.

Describe alternatives you've considered I can probably hunt down all usages within the code but it seems suboptimal. The current documentation just mentions the presence of this field and it's even typed as just string, which doesn't convey much information about it.

Additional context React Hook Form seems like a really neat and advanced library - well done!