I have a image upload component where user can upload one or multiple images at a time. When the user upload an image I always try to update the state using useState(). But the state is not updating in the very first time. How can I update the below code to make this work.
import React from 'react';
import './style.css';
import React, { useState } from 'react';
export default function App() {
const [file, setFile] = useState([]);
const uploadImages = (event) => {
console.log('NewFile=>', event.target.files);
setFile([...file, ...event.target.files]);
console.log('UpdatedFiles=>', file);
};
return (
<div>
<input
multiple
type="file"
name="photo"
id="photo"
accept="image/*"
capture="environment"
onChange={(event) => uploadImages(event)}
/>
</div>
);
}