Skip to content

Instantly share code, notes, and snippets.

@mgmgpyaesonewin
Created January 18, 2018 06:59
Show Gist options
  • Save mgmgpyaesonewin/45d218b87e4f537d567e64f87311bb95 to your computer and use it in GitHub Desktop.
Save mgmgpyaesonewin/45d218b87e4f537d567e64f87311bb95 to your computer and use it in GitHub Desktop.
Getting data from backend redux
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