snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
9
integrations/react-next-15/.eslintrc.cjs
Normal file
9
integrations/react-next-15/.eslintrc.cjs
Normal file
@@ -0,0 +1,9 @@
|
||||
/** @type {import('eslint').Linter.Config} */
|
||||
module.exports = {
|
||||
extends: ['plugin:react/jsx-runtime', 'plugin:react-hooks/recommended'],
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
}
|
||||
34
integrations/react-next-15/.gitignore
vendored
Normal file
34
integrations/react-next-15/.gitignore
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env*.local
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
34
integrations/react-next-15/README.md
Normal file
34
integrations/react-next-15/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
||||
11
integrations/react-next-15/app/_action.ts
Normal file
11
integrations/react-next-15/app/_action.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { countRef } from './make-query-client'
|
||||
|
||||
export async function queryExampleAction() {
|
||||
await Promise.resolve()
|
||||
countRef.current++
|
||||
revalidatePath('/', 'page')
|
||||
return undefined
|
||||
}
|
||||
36
integrations/react-next-15/app/client-component.tsx
Normal file
36
integrations/react-next-15/app/client-component.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
'use client'
|
||||
|
||||
import React from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Temporal } from '@js-temporal/polyfill'
|
||||
|
||||
export function ClientComponent() {
|
||||
const query = useQuery({
|
||||
queryKey: ['data'],
|
||||
queryFn: async () => {
|
||||
const { count } = await (
|
||||
await fetch('http://localhost:3000/count')
|
||||
).json()
|
||||
|
||||
return {
|
||||
text: 'data from client',
|
||||
date: Temporal.PlainDate.from('2023-01-01'),
|
||||
count,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
if (query.isPending) {
|
||||
return <div>Loading...</div>
|
||||
}
|
||||
|
||||
if (query.isError) {
|
||||
return <div>An error has occurred!</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{query.data.text} - {query.data.date.toJSON()} - {query.data.count}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
5
integrations/react-next-15/app/count/route.ts
Normal file
5
integrations/react-next-15/app/count/route.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { countRef } from '../make-query-client'
|
||||
|
||||
export const GET = () => {
|
||||
return Response.json({ count: countRef.current })
|
||||
}
|
||||
BIN
integrations/react-next-15/app/favicon.ico
Normal file
BIN
integrations/react-next-15/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
22
integrations/react-next-15/app/layout.tsx
Normal file
22
integrations/react-next-15/app/layout.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react'
|
||||
import Providers from './providers'
|
||||
import type { Metadata } from 'next'
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Create Next App',
|
||||
description: 'Generated by create next app',
|
||||
}
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
53
integrations/react-next-15/app/make-query-client.ts
Normal file
53
integrations/react-next-15/app/make-query-client.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Temporal } from '@js-temporal/polyfill'
|
||||
import { QueryClient, defaultShouldDehydrateQuery } from '@tanstack/react-query'
|
||||
import { createTson } from 'tupleson'
|
||||
import type { TsonType } from 'tupleson'
|
||||
|
||||
const plainDate = {
|
||||
deserialize: (v) => Temporal.PlainDate.from(v),
|
||||
key: 'PlainDate',
|
||||
serialize: (v) => v.toJSON(),
|
||||
test: (v) => v instanceof Temporal.PlainDate,
|
||||
} satisfies TsonType<Temporal.PlainDate, string>
|
||||
|
||||
export const countRef = {
|
||||
current: 0,
|
||||
}
|
||||
|
||||
export const tson = createTson({
|
||||
types: [plainDate],
|
||||
})
|
||||
|
||||
export function makeQueryClient() {
|
||||
return new QueryClient({
|
||||
defaultOptions: {
|
||||
hydrate: {
|
||||
/**
|
||||
* Called when the query is rebuilt from a prefetched
|
||||
* promise, before the query data is put into the cache.
|
||||
*/
|
||||
deserializeData: (data) => {
|
||||
return tson.deserialize(data)
|
||||
},
|
||||
},
|
||||
queries: {
|
||||
staleTime: 60 * 1000,
|
||||
},
|
||||
dehydrate: {
|
||||
serializeData: (data) => {
|
||||
return tson.serialize(data)
|
||||
},
|
||||
shouldDehydrateQuery: (query) => {
|
||||
return (
|
||||
defaultShouldDehydrateQuery(query) ||
|
||||
query.state.status === 'pending'
|
||||
)
|
||||
},
|
||||
shouldRedactErrors: (error) => {
|
||||
// Next.js automatically redacts errors for us
|
||||
return false
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
41
integrations/react-next-15/app/page.tsx
Normal file
41
integrations/react-next-15/app/page.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { headers } from 'next/headers'
|
||||
import React from 'react'
|
||||
import { HydrationBoundary, dehydrate } from '@tanstack/react-query'
|
||||
import { Temporal } from '@js-temporal/polyfill'
|
||||
import { ClientComponent } from './client-component'
|
||||
import { makeQueryClient } from './make-query-client'
|
||||
import { queryExampleAction } from './_action'
|
||||
|
||||
export default function Home() {
|
||||
const queryClient = makeQueryClient()
|
||||
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ['data'],
|
||||
queryFn: async () => {
|
||||
const { count } = await (
|
||||
await fetch('http://localhost:3000/count', {
|
||||
headers: await headers(),
|
||||
})
|
||||
).json()
|
||||
|
||||
return {
|
||||
text: 'data from server',
|
||||
date: Temporal.PlainDate.from('2024-01-01'),
|
||||
count,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const state = dehydrate(queryClient)
|
||||
|
||||
return (
|
||||
<main>
|
||||
<HydrationBoundary state={state}>
|
||||
<ClientComponent />
|
||||
</HydrationBoundary>
|
||||
<form action={queryExampleAction}>
|
||||
<button type="submit">Increment</button>
|
||||
</form>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
39
integrations/react-next-15/app/providers.tsx
Normal file
39
integrations/react-next-15/app/providers.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
// In Next.js, this file would be called: app/providers.tsx
|
||||
'use client'
|
||||
|
||||
// Since QueryClientProvider relies on useContext under the hood, we have to put 'use client' on top
|
||||
import { QueryClientProvider, environmentManager } from '@tanstack/react-query'
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
||||
import type { QueryClient } from '@tanstack/react-query'
|
||||
import { makeQueryClient } from '@/app/make-query-client'
|
||||
|
||||
let browserQueryClient: QueryClient | undefined = undefined
|
||||
|
||||
function getQueryClient() {
|
||||
if (environmentManager.isServer()) {
|
||||
// Server: always make a new query client
|
||||
return makeQueryClient()
|
||||
} else {
|
||||
// Browser: make a new query client if we don't already have one
|
||||
// This is very important, so we don't re-make a new client if React
|
||||
// suspends during the initial render. This may not be needed if we
|
||||
// have a suspense boundary BELOW the creation of the query client
|
||||
if (!browserQueryClient) browserQueryClient = makeQueryClient()
|
||||
return browserQueryClient
|
||||
}
|
||||
}
|
||||
|
||||
export default function Providers({ children }: { children: React.ReactNode }) {
|
||||
// NOTE: Avoid useState when initializing the query client if you don't
|
||||
// have a suspense boundary between this and the code that may
|
||||
// suspend because React will throw away the client on the initial
|
||||
// render if it suspends and there is no boundary
|
||||
const queryClient = getQueryClient()
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{children}
|
||||
<ReactQueryDevtools />
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
11
integrations/react-next-15/next.config.js
Normal file
11
integrations/react-next-15/next.config.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true,
|
||||
},
|
||||
typescript: {
|
||||
ignoreBuildErrors: true,
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = nextConfig
|
||||
21
integrations/react-next-15/package.json
Normal file
21
integrations/react-next-15/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "react-next-15",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev --webpack",
|
||||
"build": "next build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@js-temporal/polyfill": "^0.4.4",
|
||||
"@tanstack/react-query": "workspace:*",
|
||||
"@tanstack/react-query-devtools": "workspace:*",
|
||||
"next": "^15.4.8",
|
||||
"react": "^19.2.1",
|
||||
"react-dom": "^19.2.1",
|
||||
"tupleson": "0.23.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.2.7",
|
||||
"@types/react-dom": "^19.2.3"
|
||||
}
|
||||
}
|
||||
34
integrations/react-next-15/tsconfig.json
Normal file
34
integrations/react-next-15/tsconfig.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".eslintrc.cjs"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user