The error I get is Property 'files' does not exist on type 'ChangeEvent<HTMLInputElement>
Why cant I access the files array from the file input?
Is this a case where useRef is ok to use?
import React from 'react';
const Photo: React.FC = () => {
const [state, setState] = useState({
photo: '',
});
const {
photo,
} = state;
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
'ChangeEvent<HTMLInputElement>
event.persist();
setState((prev) => ({
...prev,
[event.target.id]: event.target.value,
}));
console.log(state.photo) // returns nothing
console.log(event.files[0]);
// ^
// Property 'files' does not exist on type
};
return (
<div className='photo'>
<label>
Click Me
<input
type='file'
id='photo'
name='photo'
accept='image/png, image/jpeg'
onChange={onChange}
value={photo}
></input>
</label>
</div>
);
};