reset() does not clear inputs wrapped with useController unless defaultValues are set #12861
              
                Unanswered
              
          
                  
                    
                      Best-Sardar
                    
                  
                
                  asked this question in
                General
              
            Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
sandbox: https://codesandbox.io/p/devbox/v23s9q
Describe the bug
When using
useControllerto wrap input fields in react-hook-form, callingreset()without arguments does not clear the input fields unlessdefaultValuesare explicitly set for those fields inuseForm. This behavior can be unintuitive and inconvenient for large forms where setting default values for every field is impractical.Steps to reproduce
useController.defaultValuesinuseForm.reset()without any arguments.Expected behavior
Calling
reset()without arguments should clear all input fields (i.e., reset their values to empty or undefined), regardless of whetherdefaultValueswere provided.Workarounds
defaultValuesfor each field works but can be cumbersome.reset({ fieldName: '' })with empty values per field is tedious for large forms.undefinedvalues inside custom inputs by defaulting to empty string is possible but adds boilerplate.Additional context
It would be helpful if react-hook-form’s
reset()either:defaultValueswere provided,This would improve usability for large and dynamic forms using controlled components wrapped by
useController.Beta Was this translation helpful? Give feedback.
All reactions