move file reader initialization to component mount

This commit is contained in:
Calli
2023-07-03 21:44:38 +03:00
parent 1f5dca2a5b
commit 4cffd6d706

View File

@@ -15,7 +15,6 @@ export const UploadDialog = ({
}) => { }) => {
const [file, setFile] = useState(); const [file, setFile] = useState();
const fileReader = new FileReader();
const { restoreCharacters } = useContext(CharacterContext); const { restoreCharacters } = useContext(CharacterContext);
const error = new Error("Invalid input"); const error = new Error("Invalid input");
@@ -33,6 +32,7 @@ export const UploadDialog = ({
return characters; return characters;
}; };
useEffect(() => { useEffect(() => {
const fileReader = new FileReader();
if (file) { if (file) {
fileReader.onload = (event) => { fileReader.onload = (event) => {
if (!event || event.target === null) return; if (!event || event.target === null) return;