I'm having trouble setting the state with FileReader's onLoad. The goal is to display multiple images and update the state.
I have read nearly all of the stackoverflow posts and I have tried my best to familiarize myself with the File/FileReader API. Yet, when I try to update my state- the React Developer Tools doesn't have by state updating.
I expect to see two photos on my page and my photoList state to be updated, however, it's not showing up.
class App extends Component{ constructor() { super(); this.state = { photoList: [] }; } onSelectFile = event => { event.preventDefault(); const { photoList } = this.state; const { imageFile } = event.target; for( let i = 0; i < imageFile; i++){ let reader = new FileReader(); let file = imageFile[i] reader.onload = (e) => { const { result } = e.target this.setState({ photoList: [...photoList, result] }) } reader.readAsDataURL(file) } } render() { const { photoList } = this.state; return ( <div> <input type="file" accept="image/jpeg, image/png" multiple onChange={this.onSelectFile} /> <img src={ photoList } alt=""/> </div> ); } }