Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli committed Nov 3, 2024
1 parent 68df262 commit 35b842a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 145 deletions.
9 changes: 0 additions & 9 deletions examples/visualization/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,12 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<li>
<details>
<summary>@suspensive/react</summary>
<li>
<Link href="/react/Suspense/clientOnly">{`<Suspense clientOnly/>`}</Link>
</li>
<li>
<Link href="/react/DevMode">{`<DevMode/>`}</Link>
</li>
<li>
<Link href="/react/Delay">{`<Delay/>`}</Link>
</li>
<li>
<Link href="/react/ErrorBoundary/shouldCatch">{`<ErrorBoundary/>`} shouldCatch prop</Link>
</li>
<li>
<Link href="/react/SuspensiveError">SuspensiveError (internal api)</Link>
</li>
<li>
<Link href="/react/zodSearchParams">zod: no param</Link>
</li>
Expand Down
74 changes: 43 additions & 31 deletions examples/visualization/src/app/react-query/SuspenseQuery/page.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
'use client'

import { ErrorBoundary, Suspense } from '@suspensive/react'
import { SuspenseQuery } from '@suspensive/react-query'
import { SuspenseQuery, queryOptions, usePrefetchQuery } from '@suspensive/react-query'
import axios from 'axios'
import { Spinner } from '~/components/uis'

const query = {
user: (userId: number) =>
queryOptions({
queryKey: ['users', userId],
queryFn: () =>
axios
.get<{
id: number
username: string
age: number
}>(`https://dummyjson.com/users/${userId}`)
.then(({ data }) => data),
}),
products: () =>
queryOptions({
queryKey: ['products'],
queryFn: () =>
axios
.get<{
products: Array<{
id: number
title: string
price: number
}>
}>(`https://dummyjson.com/products`)
.then(({ data }) => data),
}),
}

export default function Page() {
const userId = 1
usePrefetchQuery(query.user(userId))
usePrefetchQuery(query.products())

return (
<ErrorBoundary fallback={({ error }) => <>{error.message}</>}>
<Suspense clientOnly fallback={<Spinner />}>
<Suspense clientOnly fallback={<ExpensiveSpinner ms={2000} />}>
<div>
<SuspenseQuery
queryKey={['users', userId]}
queryFn={() =>
axios
.get<{
id: number
username: string
age: number
}>(`https://dummyjson.com/users/${userId}`)
.then(({ data }) => data)
}
>
{({ data: user }) => <h1>{user.username}</h1>}
</SuspenseQuery>
<SuspenseQuery
queryKey={['products']}
queryFn={() =>
axios
.get<{
products: Array<{
id: number
title: string
price: number
}>
}>(`https://dummyjson.com/products`)
.then(({ data }) => data)
}
select={(data) => data.products}
>
<SuspenseQuery {...query.user(userId)}>{({ data: user }) => <h1>{user.username}</h1>}</SuspenseQuery>
<SuspenseQuery {...query.products()} select={(data) => data.products}>
{({ data: products }) => (
<div>
{products.map((product) => (
Expand All @@ -54,3 +58,11 @@ export default function Page() {
</ErrorBoundary>
)
}

const ExpensiveSpinner = ({ ms }: { ms: number }) => {
if (typeof window !== 'undefined') {
const start = Date.now()
while (Date.now() - start < ms) {}
}
return <Spinner />
}
34 changes: 0 additions & 34 deletions examples/visualization/src/app/react/DevMode/page.tsx

This file was deleted.

33 changes: 0 additions & 33 deletions examples/visualization/src/app/react/Suspense/clientOnly/page.tsx

This file was deleted.

38 changes: 0 additions & 38 deletions examples/visualization/src/app/react/SuspensiveError/page.tsx

This file was deleted.

0 comments on commit 35b842a

Please sign in to comment.