'How to rest input ref in mui textfield?
I want to clear the input of a text field after certain action but I am getting the following error (The value of the input element, required for a controlled component.)
const emailRef = useRef<TextFieldProps>(null);
// Clear logic
emailRef.current?.value = null;
<TextField
className={classes.root}
margin='normal'
variant='outlined'
required
fullWidth
id='email'
label='Email Address'
name='email'
autoComplete='email'
autoFocus
inputRef={emailRef}
inputProps={{
style: {
transitionDelay: '9999s',
},
}}
/>
Solution 1:[1]
Instead of using emailRef.current?.value = null; use this-
emailRef.current?.value = '';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jatin sharma |
