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

Warning: A component is changing an uncontrolled input of type text to be controlled. #133

Closed
chungweileong94 opened this issue Jan 6, 2020 · 7 comments

Comments

@chungweileong94
Copy link

Describe the bug
I'm currently using Controller with MUI TextField, and it was amazing, but I keep getting this error: Warning: A component is changing an uncontrolled input of type text to be controlled., I have to set an empty string to as the default value to solve the problem, which I think it should done it by default.

To Reproduce
Steps to reproduce the behavior:

  1. Use Controller with MUI TextField
  2. Start typing something in the TextField

Codesandbox link
https://codesandbox.io/embed/react-hook-form-controlled-warning-demo-l7k6h?fontsize=14&hidenavigation=1&theme=dark

Expected behavior
No error/warning

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Microsoft Edge (Chromium)
  • Version 79.0.309.58

Additional context
A similar issue that i found from react-hook-form-input: react-hook-form/input#31

@bluebill1049
Copy link
Member

bluebill1049 commented Jan 6, 2020

we may need to ask user to supply default value, either at input level or useForm level. RHF shouldn't assume input's default value. I will update the doc to reflect that.

@bluebill1049 bluebill1049 transferred this issue from react-hook-form/react-hook-form Jan 6, 2020
@chungweileong94
Copy link
Author

@bluebill1049 Yeah, you got the point, assuming default value might break some input components.
Will the defaultValues in useForm overwrites the defaultvalue in Controller? Since I pretty much wrap every input component with Controller with an empty string as defaultValue.

@bluebill1049
Copy link
Member

inline defaultValue will overwrite useForm defaultValues

@bluebill1049
Copy link
Member

I have updated the doc :) take a look hopefully make sense.

@bluebill1049
Copy link
Member

at controller section: https://react-hook-form.com/api#Controller

@Shelagh-Lewins
Copy link

It seems that if you use 'reset' with Controller, you must explicitly reset each input to avoid an "Uncontrolled inputs" error. It would be great if this could be mentioned in the Controller docs.

@harshilparmar
Copy link

inline defaultValue will overwrite useForm defaultValues

Thanks 😊

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants