I have the following piece of code in my app:
const [files, setFiles] = useState(null);
const onHandleChange = useCallback((e) => {
const fileReader = new FileReader();
fileReader.readAsText(e.target.files[0], "UTF-8");
fileReader.onload = e => {
console.log("e.target.result", e.target.result);
setFiles(e.target.result);
};
console.log(JSON.stringify(files));
});
I then pass onHandleChange to a component that I import using:
<Sidebar onSave={onSave} onRestore={onRestore} onReset={onReset} setElements={setElements} removeElements = {removeElements} onDownload={onDownload}
onHandleChange={onHandleChange}/>
However, the JSON.stringify gives me a null. I'm not quite sure why. I know the file is read because the console.log shows me the JSON I uploaded.