resolvers
resolvers copied to clipboard
`raw: true` option on ZodResolver not passing copy of form submission values
Describe the bug
When passing the raw option to the zodResolver function, it seems to be passing the object that RHF uses to manage the state of the form into handleSubmit rather than a snapshot of the submitted form values on submission.
The codesandbox shows a simplified example where if you take the values from the handleSubmit and put them into state, then change the value of a field in the form, it's changing the value of the object in state (without using setState). You can check the value of what's stored in state by pressing the button to re-render the page and checking the console log.
To Reproduce Steps to reproduce the behavior:
- Go to Codesandbox
- fill in the form & submit
- the values submitted get stored in state and rendered on screen
- change a value in the form field and don't submit
- press the re-render button to re-render the component.
- see that the value stored in state is now different without handleSubmit being called or the setState function being called
Codesandbox link (Required) Include a codesandbox will help us to investigate the issue quicker. Codesandbox using zodResolver
Expected behavior
The handleSubmit function should pass a copy of the current raw form values, rather than an object which is still being manipulated by RHF. To me, raw means the form values before they were processed by the schema, rather than the original object which is being continually manipulated by RHF.
Additional context
It doesn't do this if you don't pass raw: true as an argument to the resolver