I've been trying to assign as a state the contents of a .txt file uploaded locally via an input tag. I used File Reader, however although the content of the files is printed, the state is not changed according to React dev tools.
Here's the code:
handleFile = (file) => { var fileReader = new FileReader() fileReader.readAsText(file) fileReader.onloadend = function (e) { var content = e.target.result console.log(content) this.setState={ text: content } } The function handleFile is being called here:
<input type="file" accept='.txt' className="custom-file-input" id="customFile" onChange={e => this.handleFile(e.target.files[0])} /> Thanks a lot
content = await file.text()