Created
January 18, 2018 06:59
-
-
Save mgmgpyaesonewin/45d218b87e4f537d567e64f87311bb95 to your computer and use it in GitHub Desktop.
Getting data from backend redux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cache from 'memory-cache'; | |
const getAndCache = (endpoint) => { | |
const cachedData = cache.get(endpoint); | |
if (cachedData) { | |
return Promise.resolve(cachedData); | |
} | |
return fetch(`${BASE_URL}/${endpoint}`, { | |
headers: { | |
...buildHeaders(), | |
}, | |
}) | |
.catch(bail) | |
// .then(checkContentType) | |
.then(checkStatusAndParseJSON) | |
.then(res => cache.put(endpoint, res, DEFAULT_CACHE_TIME)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment