Skip to content

Commit fb67358

Browse files
authored
docs: typescript example docs (TanStack#1511)
* (docs): add typescript examples docs page * (docs): fix typescript example - eslint complains about use-before-defined - added missing react types * (docs): fix typescript example - eslint complains about use-before-defined - added missing react types * (docs): add node types * (docs): update react-query to the latest version in typescript example * (docs): add typescript example to navigation * (docs): make the typescript example open on pages/index.tsx
1 parent e69b391 commit fb67358

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

docs/src/manifests/manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@
246246
"path": "/examples/optimistic-updates",
247247
"editUrl": "/examples/optimistic-updates.mdx"
248248
},
249+
{
250+
"title": "Optimistic Updates in TypeScript",
251+
"path": "/examples/optimistic-updates-typescript",
252+
"editUrl": "/examples/optimistic-updates-typescript.mdx"
253+
},
249254
{
250255
"title": "Pagination",
251256
"path": "/examples/pagination",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
id: optimistic-updates-typescript
3+
title: Optimistic Updates in TypeScript
4+
toc: false
5+
---
6+
7+
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-query/tree/master/examples/optimistic-updates-typescript)
8+
- [View Source](https://github.com/tannerlinsley/react-query/tree/master/examples/optimistic-updates-typescript)
9+
10+
<iframe
11+
src="https://codesandbox.io/embed/github/tannerlinsley/react-query/tree/master/examples/optimistic-updates-typescript?autoresize=1&fontsize=14&module=%2Fpages%2Findex.tsx&theme=dark"
12+
title="tannerlinsley/react-query: optimistic-updates-typescript"
13+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
14+
style={{
15+
width: '100%',
16+
height: '80vh',
17+
border: '0',
18+
borderRadius: 8,
19+
overflow: 'hidden',
20+
position: 'static',
21+
zIndex: 0,
22+
}}
23+
></iframe>

examples/optimistic-updates-typescript/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"main": "index.js",
55
"license": "MIT",
66
"dependencies": {
7+
"@types/react": "^17.0.0",
8+
"@types/node": "14.14.14",
79
"axios": "^0.19.2",
810
"isomorphic-unfetch": "3.0.0",
911
"next": "9.2.2",
1012
"react": "^17.0.1",
1113
"react-dom": "^17.0.1",
12-
"react-query": "^3.2.0-beta.32",
13-
"react-query-devtools": "^3.0.0-beta.1",
14+
"react-query": "3.5.1",
1415
"typescript": "^4.1.2"
1516
},
1617
"scripts": {

examples/optimistic-updates-typescript/pages/index.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,10 @@ import {
99
QueryClientProvider,
1010
UseQueryOptions,
1111
} from 'react-query'
12-
import { ReactQueryDevtools } from 'react-query-devtools'
12+
import { ReactQueryDevtools } from 'react-query/devtools'
1313

1414
const client = new QueryClient()
1515

16-
export default function App() {
17-
return (
18-
<QueryClientProvider client={client}>
19-
<Example />
20-
<TodoCounter />
21-
<ReactQueryDevtools initialIsOpen />
22-
</QueryClientProvider>
23-
)
24-
}
25-
2616
type Todos = {
2717
items: readonly {
2818
id: string
@@ -37,7 +27,7 @@ async function fetchTodos(): Promise<Todos> {
3727
}
3828

3929
function useTodos<TData = Todos>(
40-
options?: UseQueryOptions<TData, AxiosError, Todos>
30+
options?: UseQueryOptions<Todos, AxiosError, TData>
4131
) {
4232
return useQuery('todos', fetchTodos, options)
4333
}
@@ -143,3 +133,13 @@ function Example() {
143133
</div>
144134
)
145135
}
136+
137+
export default function App() {
138+
return (
139+
<QueryClientProvider client={client}>
140+
<Example />
141+
<TodoCounter />
142+
<ReactQueryDevtools initialIsOpen />
143+
</QueryClientProvider>
144+
)
145+
}

0 commit comments

Comments
 (0)