Skip to content

Commit b58da75

Browse files
docs(examples): Modernise Next.js examples (#7706)
* docs(examples): Update react/auto-refetching * Update infinite-query-with-max-pages, load-more-infinite-scroll * Upgrade react/nextjs * More projects * Update playground * Update prefetching * Cleanup deps * Disable typescript during next build * Fix eslint plugin * Final changes
1 parent 8d0ba7e commit b58da75

File tree

89 files changed

+589
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+589
-379
lines changed

docs/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@
903903
},
904904
{
905905
"label": "Basic",
906-
"to": "framework/solid/examples/basic-typescript"
906+
"to": "framework/solid/examples/basic"
907907
},
908908
{
909909
"label": "Basic w/ GraphQL-Request",

examples/angular/infinite-query-with-max-pages/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@tanstack/query-example-angular-infinite-query-with-max-pages",
3-
"version": "0.0.0",
3+
"private": true,
4+
"type": "module",
45
"scripts": {
56
"ng": "ng",
67
"start": "ng serve",
78
"build": "ng build",
89
"watch": "ng build --watch --configuration development"
910
},
10-
"private": true,
1111
"dependencies": {
1212
"@angular/common": "^17.3.10",
1313
"@angular/compiler": "^17.3.10",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

examples/react/auto-refetching/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const nextConfig = {
55
eslint: {
66
ignoreDuringBuilds: true,
77
},
8+
typescript: {
9+
ignoreBuildErrors: true,
10+
},
811
}
912

1013
export default nextConfig

examples/react/auto-refetching/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
"dependencies": {
1111
"@tanstack/react-query": "^5.50.1",
1212
"@tanstack/react-query-devtools": "^5.50.1",
13-
"isomorphic-unfetch": "4.0.2",
1413
"next": "^14.2.4",
1514
"react": "^18.2.0",
1615
"react-dom": "^18.2.0"
16+
},
17+
"devDependencies": {
18+
"@types/react": "^18.2.79",
19+
"@types/react-dom": "^18.2.25",
20+
"typescript": "5.3.3"
1721
}
1822
}

examples/react/auto-refetching/src/pages/api/data.js renamed to examples/react/auto-refetching/src/pages/api/data.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import type { NextApiRequest, NextApiResponse } from 'next'
2+
13
// an simple endpoint for getting current list
24
let list = ['Item 1', 'Item 2', 'Item 3']
35

4-
export default async (req, res) => {
6+
export default async (
7+
req: NextApiRequest,
8+
res: NextApiResponse<typeof list>,
9+
) => {
510
if (req.query.add) {
611
if (!list.includes(req.query.add)) {
712
list.push(req.query.add)

examples/react/auto-refetching/src/pages/index.js renamed to examples/react/auto-refetching/src/pages/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from 'react'
22

3-
//
4-
53
import {
6-
useQuery,
7-
useQueryClient,
8-
useMutation,
94
QueryClient,
105
QueryClientProvider,
6+
useMutation,
7+
useQuery,
8+
useQueryClient,
119
} from '@tanstack/react-query'
1210
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
1311

@@ -28,7 +26,7 @@ function Example() {
2826

2927
const { status, data, error, isFetching } = useQuery({
3028
queryKey: ['todos'],
31-
queryFn: async () => {
29+
queryFn: async (): Promise<Array<string>> => {
3230
const response = await fetch('/api/data')
3331
return await response.json()
3432
},
@@ -37,7 +35,7 @@ function Example() {
3735
})
3836

3937
const addMutation = useMutation({
40-
mutationFn: (add) => fetch(`/api/data?add=${add}`),
38+
mutationFn: (add: string) => fetch(`/api/data?add=${add}`),
4139
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
4240
})
4341

@@ -51,7 +49,7 @@ function Example() {
5149

5250
return (
5351
<div>
54-
<h1>Auto Refetch with stale-time set to 1s)</h1>
52+
<h1>Auto Refetch with stale-time set to {intervalMs}ms</h1>
5553
<p>
5654
This example is best experienced on your own machine, where you can open
5755
multiple tabs to the same localhost server and see your changes
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["dom", "dom.iterable", "esnext"],
4+
"allowJs": true,
5+
"skipLibCheck": true,
6+
"strict": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"noEmit": true,
9+
"esModuleInterop": true,
10+
"module": "esnext",
11+
"moduleResolution": "Bundler",
12+
"resolveJsonModule": true,
13+
"isolatedModules": true,
14+
"jsx": "preserve",
15+
"incremental": true
16+
},
17+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
18+
"exclude": ["node_modules"]
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

examples/react/infinite-query-with-max-pages/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const nextConfig = {
55
eslint: {
66
ignoreDuringBuilds: true,
77
},
8+
typescript: {
9+
ignoreBuildErrors: true,
10+
},
811
}
912

1013
export default nextConfig

0 commit comments

Comments
 (0)