Skip to content

Instantly share code, notes, and snippets.

@mfrachet
Created January 11, 2019 12:58
Show Gist options
  • Save mfrachet/236c4f48352d50a1c21ca56fe764b0c1 to your computer and use it in GitHub Desktop.
Save mfrachet/236c4f48352d50a1c21ca56fe764b0c1 to your computer and use it in GitHub Desktop.
React cache
const getBulbasaur = () =>
fetch("https://pokeapi.co/api/v2/pokemon/1/").then(res => res.json());
const ApiResource = createResource(getBulbasaur);
const Pokemon = () => {
const bulbasaur = ApiResource.read();
return <div>Hello {bulbasaur.name}</div>;
};
const App = () => (
<Suspense fallback={<div>Let's wait :D</div>}>
<Pokemon />
</Suspense>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment