Reputation: 19
the value is not set in state hooks
`
> const Post = (props) => {
>
> const [selectedFile, setselectedFile] = React.useState([]);
>
> const upload=event=>{
>
> setselectedFile(selectedFile,event.target.files[0]);
>
> }
>
> }`
Upvotes: 0
Views: 26
Reputation: 19
I finally fix this issue.. Problem is here
const [selectedFile, setselectedFile] = React.useState([]); this is incorrect..
const [selectedFile, setselectedFile] = React.useState(""); Correct Finally this can fix this issuee
Upvotes: 0
Reputation: 2869
you only need to set the current state.
If you want to maintain a list of selected files then do the following
setselectedFile([...selectedFile,event.target.files[0]]);
If you only want to maintain the current file then do this
setselectedFile(event.target.files[0]);
Upvotes: 1