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