Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

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

Closed
kusmierz opened this issue Dec 12, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@kusmierz
Copy link

Describe the bug
Trying to change MUI Textfield on demo page, results a warning as follow.

Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components
    in input (created by ForwardRef(InputBase))
    in div (created by ForwardRef(InputBase))
    in ForwardRef(InputBase) (created by WithStyles(ForwardRef(InputBase)))
    in WithStyles(ForwardRef(InputBase)) (created by ForwardRef(Input))
    in ForwardRef(Input) (created by WithStyles(ForwardRef(Input)))
    in WithStyles(ForwardRef(Input)) (created by ForwardRef(TextField))
    in div (created by ForwardRef(FormControl))
    in ForwardRef(FormControl) (created by WithStyles(ForwardRef(FormControl)))
    in WithStyles(ForwardRef(FormControl)) (created by ForwardRef(TextField))
    in ForwardRef(TextField) (created by WithStyles(ForwardRef(TextField)))
    in WithStyles(ForwardRef(TextField)) (at src/index.js:91)
    in RHFInput (at src/index.js:90)
    in section (at src/index.js:88)
    in div (at src/index.js:47)
    in form (at src/index.js:43)
    in ThemeProvider (at src/index.js:42)
    in App (at src/index.js:166)

To Reproduce
Steps to reproduce the behavior:

  1. Go to demo page, results a warning as follow.
  2. Open CodeSandbox Browser's Console
  3. Click on 'MUI TextField'
  4. Type anything
  5. See the error

Codesandbox link
https://codesandbox.io/s/react-hook-form-hookforminput-rzu9s

Expected behavior
No error at all

Screenshots
image

Desktop (please complete the following information):

  • OS: macOS 10.15.2
  • Browser: Chrome
  • Version: 78.0.3904.108
@zhihongl
Copy link

zhihongl commented Jul 6, 2020

Just give a default value or value={value|| ''} will solve the issue

noriaki added a commit to noriaki/bicycle-breakdown-report-app that referenced this issue Jul 16, 2020
@HiepPP
Copy link

HiepPP commented Dec 26, 2020

I'm using react hook form v6 (link demo) and meet the same error. I resolve it with the following code:
<Checkbox onChange={(e) => props.onChange(e.target.checked)} checked={props.value || false} />

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants