Filter out non-form data on reset
See original GitHub issueinterface FormData {
greeting: string;
}
// in the component
reset({greeting: 'hello', otherProp: 'something else' });
const onSubmit = handleSubmit((formData) => {
formData.otherProp === 'something else' // true;
});
Ideally, reset
would strip out any props that are not part of the form schema (in this case otherProp
). I currently call reset
when the data from the api has been returned. However, the data from the api contains all types of fields that are not part of the form schema. This becomes an issue since when I submit the formData to the api because I end up submitting additional data that I did not intend to submit. This becomes more of a problem with GraphQL since the server will actually reject requests that do not conform to the schema.
Describe the solution you’d like Ideally react-hook-form would only pick the properties that are part of the schema.
Describe alternatives you’ve considered I’m currently stripping the additional properties on my own.
btw, thank you for this amazing library. Working with forms in React has never been so easy 😃
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:16 (9 by maintainers)
Top GitHub Comments
Just tried it and it is working perfectly. Thanks for the update!
up!