Lalliantluanga Hauhnar
Lalliantluanga Hauhnar

Reputation: 201

React Hook Form and Material ui component-inputRef not working-A component is changing an uncontrolled input of type

When i try to use React hook form and material ui component i received the following error

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.

When i tried to use inputRef it is still not working.

<TextField
    autoFocus
    margin="dense"
    id="name"
    label="Name"
    type="text"
    fullWidth
    inputRef={register}
/>
{ <Controller
    as={TextField}
    name='test'
    control={control}
    placeholder='test'
>}

Upvotes: 0

Views: 1529

Answers (2)

abumalick
abumalick

Reputation: 2346

You don't need the controller for a simple TextInput field. You should get rid of it and see if your warning dissappear.

Upvotes: 0

Sourav Singh
Sourav Singh

Reputation: 955

Please set the value that will resolve your uncontrolled input problem.

value={ this.state.value || "" }

Upvotes: 1

Related Questions