Skip to content

Commit

Permalink
chore: improve slightly fallback suspense UI in suspense example
Browse files Browse the repository at this point in the history
  • Loading branch information
FaberVitale committed Mar 26, 2022
1 parent a6b7f36 commit f2d0ec6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 7 additions & 6 deletions examples/query/react/suspense/src/SuspendedPokemon.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { memo } from 'react';
import { Suspense, useState } from 'react'
import { Pokemon } from './Pokemon'
import { PokemonName } from './pokemon.data'
Expand All @@ -11,13 +12,13 @@ export interface SuspendedPokemonProps {

function BuggyComponent({ errorCount, name }:Pick<SuspendedPokemonProps, 'name'> & { errorCount: number }) {
if(!errorCount) {
throw new Error('error while rendering:' + name)
throw new Error(`error while rendering: ${name}, errorCount ${errorCount}`);
}

return <></>
}

export function SuspendedPokemon({
export const SuspendedPokemon = memo(function SuspendedPokemon({
name,
suspendOnRefetch,
throwOnIntialRender,
Expand Down Expand Up @@ -45,9 +46,9 @@ export function SuspendedPokemon({
{throwOnIntialRender && <BuggyComponent name={name} errorCount={errorCount} />}
<Suspense
fallback={
<div>
suspense fallback <br />
loading pokemon {name}
<div className={'suspense-fallback-wrapper'}>
Suspense fallback UI.<br />
Loading pokemon {name}
</div>
}
>
Expand All @@ -56,4 +57,4 @@ export function SuspendedPokemon({
</ErrorBoundary>
</div>
)
}
});
10 changes: 10 additions & 0 deletions examples/query/react/suspense/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
grid-template-columns: repeat(auto-fill, 180px);
grid-gap: 20px;
}

.suspense-fallback-wrapper {
display: flex;
place-items: center;
background: #e0e0e0;
color: #202020;
border-radius: 8px;
font-size: 1.1rem;
height: 250px;
}

0 comments on commit f2d0ec6

Please sign in to comment.