File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
examples/code-splitting/modules Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import Coroutine from 'react-coroutine' ;
3+
4+ export default Coroutine . create ( Placeholder ) ;
5+
6+ async function Placeholder ( { delay, children } ) {
7+ await new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
8+ return children ;
9+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react';
22import Coroutine from 'react-coroutine' ;
33import { BrowserRouter as Router , Route } from 'react-router-dom' ;
44import Pokemons from './PokemonAPI' ;
5+ import Placeholder from './Placeholder' ;
56
67/* Routes are using wrapped by Coroutine components for the sake of
78 async functions and generators usage. */
@@ -35,9 +36,13 @@ async function* PokemonInfoLoader({ match }) {
3536 /* This request can also be cached but that's API's implementation detail.
3637 For the example purpose, it just does new request all the time. */
3738 const pokemonInfo = Pokemons . retrieve ( match . params . pokemonId ) ;
38- /* Since API request takes time, we show a pending message immediately
39+ /* Since API request takes time sometimes , we show a pending message
3940 and then wait for requests resolving. */
40- yield < p > Loading...</ p > ;
41+ yield (
42+ < Placeholder delay = { 2000 } >
43+ < p > Loading...</ p >
44+ </ Placeholder >
45+ ) ;
4146 /* Promise.all is used pretty much for example purpose. However, it's
4247 efficient way to make concurrent requests. */
4348 const [ { default : PokemonInfo } , data ] = await Promise . all ( [ module , pokemonInfo ] ) ;
You can’t perform that action at this time.
0 commit comments