Skip to content

Instantly share code, notes, and snippets.

@luillyfe
Last active January 30, 2020 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luillyfe/eaa5b82a753ee462855e640bd0e5239f to your computer and use it in GitHub Desktop.
Save luillyfe/eaa5b82a753ee462855e640bd0e5239f to your computer and use it in GitHub Desktop.
Async rendering: React
<GridList cellHeight={160} className={classes.gridList} cols={3}>
{pokemons ? (
pokemons.map(async ({ pokemon }) => {
const url = await getPokemon(pokemon.url);
return (
<GridListTile key={pokemon.name} cols={1}>
<img src={url} alt={pokemon.name} />
</GridListTile>
);
})
) : (
<div />
)}
</GridList>
pokemons.map(async ({ pokemon }) => {
const url = await getPokemon(pokemon.url);
return (
<Suspense fallback={<h1>Loading pokemons...</h1>}>
<GridListTile key={pokemon.name} cols={1}>
<img src={url} alt={pokemon.name} />
</GridListTile>
</Suspense>
);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment