2

I am building a react app and would like to use promises to upload files to my database. When the user navigates away from this page and moves to other pages, if there is a pending promise, does it continue despite the page changes? If I were to store my file objects in a global state, can the promise continue executing despite a page change?

shinzo
  • 31
  • 3
  • 1
    What did you try? – Charlie Jul 13 '20 at 05:26
  • Why does that matter? Whatever you'd want to do with that Promise, you couldn't anyway. I guess, the real question you should be asking is "will my request succeed". The Promise has nothing to do with that. – Kaiido Jul 13 '20 at 05:42
  • The promise is a contract, it has no influence on the process of an action. – Estradiaz Jul 13 '20 at 06:15

1 Answers1

0

Yes it will continue executing even after page change. If you were to update some state after in the unmounted component it would have thrown an error.

Though as you are using a global state it should not be a problem.

Refer Cancel a promise when a component is unmounted in ReactJS for opposite use-case.

kooskoos
  • 4,622
  • 1
  • 12
  • 29