File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
examples/query/react/suspense/src Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change
1
+ import { memo } from 'react' ;
1
2
import { Suspense , useState } from 'react'
2
3
import { Pokemon } from './Pokemon'
3
4
import { PokemonName } from './pokemon.data'
@@ -11,13 +12,13 @@ export interface SuspendedPokemonProps {
11
12
12
13
function BuggyComponent ( { errorCount, name } :Pick < SuspendedPokemonProps , 'name' > & { errorCount : number } ) {
13
14
if ( ! errorCount ) {
14
- throw new Error ( ' error while rendering:' + name )
15
+ throw new Error ( ` error while rendering: ${ name } , errorCount ${ errorCount } ` ) ;
15
16
}
16
17
17
18
return < > </ >
18
19
}
19
20
20
- export function SuspendedPokemon ( {
21
+ export const SuspendedPokemon = memo ( function SuspendedPokemon ( {
21
22
name,
22
23
suspendOnRefetch,
23
24
throwOnIntialRender,
@@ -45,9 +46,9 @@ export function SuspendedPokemon({
45
46
{ throwOnIntialRender && < BuggyComponent name = { name } errorCount = { errorCount } /> }
46
47
< Suspense
47
48
fallback = {
48
- < div >
49
- suspense fallback < br />
50
- loading pokemon { name }
49
+ < div className = { 'suspense-fallback-wrapper' } >
50
+ Suspense fallback UI. < br />
51
+ Loading pokemon { name }
51
52
</ div >
52
53
}
53
54
>
@@ -56,4 +57,4 @@ export function SuspendedPokemon({
56
57
</ ErrorBoundary >
57
58
</ div >
58
59
)
59
- }
60
+ } ) ;
Original file line number Diff line number Diff line change 8
8
grid-template-columns : repeat (auto-fill, 180px );
9
9
grid-gap : 20px ;
10
10
}
11
+
12
+ .suspense-fallback-wrapper {
13
+ display : flex;
14
+ place-items : center;
15
+ background : # e0e0e0 ;
16
+ color : # 202020 ;
17
+ border-radius : 8px ;
18
+ font-size : 1.1rem ;
19
+ height : 250px ;
20
+ }
You can’t perform that action at this time.
0 commit comments