'what should be the default value of file in react-typescript in useState
How do I initialize a file through useState in React Typescript?
const [images, setImages] = useState<File>();
const [formData, setFormData] = useState({
image: File
});
I am getting file as undefined when I am trying to upload an image.
Solution 1:[1]
As I understand your question, for instance, you could use
onChange={(event: ChangeEvent<HTMLInputElement>) => {
if (!event.target.files) return
setImages(event.target.files[0])
}}
inside input tug.
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 | TIshow |
