I have a problem in react js. I create empty Array of useState like this code :
const [fileUploadName, setUploadFileName] = useState([])
I want push my my file atteched name into this array , this is my code :
const InputFileHandler = event => {
file = event.target.files[0];
setUploadFileName(oldNames => [...oldNames, file.name])
const AllfileNames= fileUploadName
}
When I push data into array at first time ,AllfileNames is '[]', but when I push data at second time AllfileNames is the name of first attached name for example:
firstAttachName = 'download.jpg';
secondAttachName = 'download1.jpg';
In first push, AllfileNames give me this data: []
In second push, AllfileNames give me this data: ['download.jpg']
What is the problem with this code?