MCPcopy Create free account
hub / github.com/epicweb-dev/react-suspense / App

Function App

exercises/06.optimization/02.solution.cache/index.tsx:9–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7const shipFallbackSrc = '/img/fallback-ship.png'
8
9function App() {
10 const [shipName, setShipName] = useState('Dreadnought')
11 const [isTransitionPending, startTransition] = useTransition()
12 const isPending = useSpinDelay(isTransitionPending, {
13 delay: 300,
14 minDuration: 350,
15 })
16 return (
17 <div className="app-wrapper">
18 <div className="app">
19 <ErrorBoundary
20 fallback={
21 <div className="app-error">
22 <p>Something went wrong!</p>
23 </div>
24 }
25 >
26 <Suspense
27 fallback={<img style={{ maxWidth: 400 }} src={shipFallbackSrc} />}
28 >
29 <div className="search">
30 <ShipSearch
31 onSelection={(selection) => {
32 startTransition(() => setShipName(selection))
33 }}
34 />
35 </div>
36 <div className="details" style={{ opacity: isPending ? 0.6 : 1 }}>
37 <ErrorBoundary fallback={<ShipError shipName={shipName} />}>
38 {shipName ? (
39 <Suspense fallback={<ShipFallback shipName={shipName} />}>
40 <ShipDetails shipName={shipName} />
41 </Suspense>
42 ) : (
43 <p>Select a ship from the list to see details</p>
44 )}
45 </ErrorBoundary>
46 </div>
47 </Suspense>
48 </ErrorBoundary>
49 </div>
50 </div>
51 )
52}
53
54function ShipSearch({
55 onSelection,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected