export const cachedFetch = url => { const key = `@MySuperStore:${url}`; return AsyncStorage.getItem(key) .then(data => { if (!data) { return Promise.reject("no data found in async storage"); } console.log("found data on disk"); return JSON.parse(data); }) .catch(() => { console.log("didn't find data on disk, fetching"); return fetch(url).then(response => { if (response.ok) { return response.json().then(data => { AsyncStorage.setItem(key, JSON.stringify(data)); return data; }); } return Promise.reject("unable to load data"); }); }); };