I have a simple state to store the files uploaded
const [files, setFiles] = useState([]);
When I submit/create the form it uploads normally,
The issue is when I try to save to draft, it puts the files
to initial state.
useEffect(() => {
if (halfFilledForm) {
const unblock = history.block((_) => {
if (window.confirm("Do you want to save the Story Idea as Draft?")) {
console.log(files) // prints to `[]`
saveAsDraft();
}
return true;
});
return () => {
unblock();
};
}}, [halfFilledForm]);
Juan Pablo Isaza
I needed to pass files
as dependency to useEffect
hook