• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

13
Views
React clears state on window.confirm

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]);
about 1 month ago ·

Juan Pablo Isaza

1 answers
Answer question

0

I needed to pass files as dependency to useEffect hook

about 1 month ago · Juan Pablo Isaza Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.