-
-
Save juandc/571da377d91e780567516ba3e5e74ed3 to your computer and use it in GitHub Desktop.
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
// NOTE: This is NOT how you'd normally use suspense. | |
// You'll either use react-cache or libraries that use react-cache. | |
// This is only for instructional purposes. | |
const cache = {} | |
function FetchPokemon({pokemonName}) { | |
const pokemon = cache[pokemonName] | |
if (!pokemon) { | |
const promise = fetchPokemon(pokemonName).then( | |
pokemon => (cache[pokemonName] = pokemon), | |
) | |
throw promise | |
} | |
return <pre>{JSON.stringify(pokemon || 'Unknown', null, 2)}</pre> | |
} | |
function PokemonInfo({pokemonName}) { | |
return ( | |
<React.Placeholder fallback="loading..."> | |
<FetchPokemon pokemonName={pokemonName} /> | |
</React.Placeholder> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment