-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathindex.tsx
More file actions
45 lines (38 loc) · 1.07 KB
/
index.tsx
File metadata and controls
45 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { queryOptions, useSuspenseQuery } from '@tanstack/react-query'
import { createFileRoute } from '@tanstack/react-router'
import * as React from 'react'
type Profile = {
isDefault: boolean
profileId: string
}
const profilesQueryOptions = queryOptions({
queryKey: ['profiles'],
queryFn: async (): Promise<Array<Profile>> => {
await new Promise((resolve) => setTimeout(resolve, 1000))
return [
{ profileId: 'default-profile', isDefault: true },
{ profileId: 'secondary-profile', isDefault: false },
]
},
retry: false,
})
export const Route = createFileRoute('/')({
component: Home,
})
function Home() {
return (
<main>
<h1>Profiles</h1>
<React.Suspense fallback={<p data-testid="loading">loading</p>}>
<ActiveProfile />
</React.Suspense>
</main>
)
}
function ActiveProfile() {
const profiles = useSuspenseQuery(profilesQueryOptions).data
const activeProfile = profiles.find((profile) => profile.isDefault)
return (
<p data-testid="active-profile">{activeProfile?.profileId ?? 'missing'}</p>
)
}