I have added a simple TextField from Material-UI into my landing page but cannot type in the React input field. I'm not sure what is causing the issue and have double-checked the following issues:
- Proper casing of
onChange
(notonchange
) - Input value must be the state
this.state
vsstate
; the former causes aTypeError: Cannot read properties of undefined (reading 'state')
.type="text"
vs.type="number"
; both options don't allow for typing in the text field
Below is my code for the TextField
, declaring state
, and handling the change in input field.
import TextField from '@material-ui/core/TextField';
...
const [state, setState] = useState({
ImageNumber: '',
});
const handleChange = (event) => {
setState({
...state,
[event.target.number]: event.target.value,
});
};
...
<TextField label="" number="ImageNumber" type="text" value={state.ImageNumber} variant="outlined" onChange={handleChange} />