I have a function that is dependent on a Promise being resolved from an async action (API fetch).
The async action needs to either return the Fetch promise, or return a promise that resolves when the Fetch completes.
However, the Fetch should only happen once.
I could store the fetch promise in a global variable, and return that, but is that an anti-pattern in Redux? Should the Promise be in the Redux store, since it's part of the application state?
Example code:
//Should this be in Redux Store?
var promise = null;
myfunction() {
doAsyncTask().then(() => {
//Continue
});
}
doAsyncTask() {
if(promise === null) {
promise = fetch('URI');
}
return promise;
}