Search code examples
javascriptreactjses6-promise

Javascript Promises-- what happens on page change?


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?


Solution

  • 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.