I'm facing a problem, probably a very simple one, but I'm stuck in since hours so I would like to ask for your help.
I have an simple File Input and I want to set this files to state to upload the files later when submitting the form.
const [inputTattoos, setInputTattoos] = useState<[{}]>();
const handleImageChange = async ({
currentTarget: input,
}: React.ChangeEvent<HTMLInputElement>) => {
if (input.files === null) return;
console.log(input.files);
setInputTattoos([{ ...input.files }]);
With this code I'm able to write the files into state, but this is not the way I want to store it on State because my State looks like this:
I have an Array and inside it an object with objects. What I'm actually get from input.files is just an array with objects but I'm not able to store this input.files like I get it on my console. I tried a lot of solutions but this is the only way I found which works. With other solutions I always get an empty object or a FileList(undefined) in State for example with this solution:
const [inputTattoos, setInputTattoos] = useState<FileList>()
const handleImageChange = async ({
currentTarget: input,
}: React.ChangeEvent<HTMLInputElement>) => {
if (input.files === null) return;
console.log(input.files);
setInputTattoos(input.files);
What's wrong here? Thank you!
