Skip to content
Advertisement

how to put a file in state variable with react hooks

I’m trying to upload a picture using react hooks

JavaScript

however I’m getting the following error:

JavaScript

when I change the onChangePicture to

JavaScript

the picture variable is undefined,

any help would be appreciated.

Advertisement

Answer

I think you meant to do:

JavaScript

This will concatenate the first file to all current files.

Remember to use const [picture, setPicture] = useState([]); as to make sure it doesn’t break the first time around

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement