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

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

当我尝试使用 React 钩子形式和 material ui 组件时,我收到以下错误

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.

当我尝试使用 inputRef 时,它仍然无法正常工作。

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

请设置将解决您的不受控制的输入问题的值。

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

简单的 TextInput 字段不需要控制器。你应该摆脱它,看看你的警告是否消失。