Open History to see the last commit
1---
2id: request-waterfalls
3title: Performance & Request Waterfalls
4ref: docs/framework/react/guides/request-waterfalls.md
5replace: { 'react-query': 'preact-query', 'React': 'Preact' }
6---
7β
8[//]: # 'LazyExample'
9β
10```tsx
11import { lazy } from 'preact/iso'
12// This lazy loads the GraphFeedItem component, meaning
13// it wont start loading until something renders it
14const GraphFeedItem = lazy(() => import('./GraphFeedItem'))
15β
16function Feed() {
17 const { data, isPending } = useQuery({
18 queryKey: ['feed'],
19 queryFn: getFeed,
20 })
21β
22 if (isPending) {
23 return 'Loading feed...'
24 }
25β
26 return (
27 <>
28 {data.map((feedItem) => {
29 if (feedItem.type === 'GRAPH') {
30 return <GraphFeedItem key={feedItem.id} feedItem={feedItem} />
31 }
32β
33 return <StandardFeedItem key={feedItem.id} feedItem={feedItem} />
34 })}
35 </>
36 )
37}
38β
39// GraphFeedItem.tsx
40function GraphFeedItem({ feedItem }) {
41 const { data, isPending } = useQuery({
42 queryKey: ['graph', feedItem.id],
43 queryFn: getGraphDataById,
44 })
45β
46 ...
47}
48```
49β
50[//]: # 'LazyExample'