Skip to content

Commit 893b99c

Browse files
committed
docs now reference react docs (most of them atleast)
1 parent 9c72beb commit 893b99c

Some content is hidden

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

44 files changed

+93
-5219
lines changed

docs/framework/preact/comparison.md

Lines changed: 0 additions & 111 deletions
This file was deleted.

docs/framework/preact/devtools.md

Lines changed: 0 additions & 196 deletions
This file was deleted.

docs/framework/preact/graphql.md

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
11
---
22
id: graphql
33
title: GraphQL
4+
ref: docs/framework/react/graphql.md
5+
replace: { 'React': 'Preact', 'react-query': 'preact-query' }
46
---
5-
6-
Because Preact Query's fetching mechanisms are agnostically built on Promises, you can use Preact Query with literally any asynchronous data fetching client, including GraphQL!
7-
8-
> Keep in mind that Preact Query does not support normalized caching. While a vast majority of users do not actually need a normalized cache or even benefit from it as much as they believe they do, there may be very rare circumstances that may warrant it so be sure to check with us first to make sure it's truly something you need!
9-
10-
[//]: # 'Codegen'
11-
12-
## Type-Safety and Code Generation
13-
14-
Preact Query, used in combination with `graphql-request^5` and [GraphQL Code Generator](https://graphql-code-generator.com/) provides full-typed GraphQL operations:
15-
16-
```tsx
17-
import request from 'graphql-request'
18-
import { useQuery } from '@tanstack/preact-query'
19-
20-
import { graphql } from './gql/gql'
21-
22-
const allFilmsWithVariablesQueryDocument = graphql(/* GraphQL */ `
23-
query allFilmsWithVariablesQuery($first: Int!) {
24-
allFilms(first: $first) {
25-
edges {
26-
node {
27-
id
28-
title
29-
}
30-
}
31-
}
32-
}
33-
`)
34-
35-
function App() {
36-
// `data` is fully typed!
37-
const { data } = useQuery({
38-
queryKey: ['films'],
39-
queryFn: async () =>
40-
request(
41-
'https://swapi-graphql.netlify.app/.netlify/functions/index',
42-
allFilmsWithVariablesQueryDocument,
43-
// variables are type-checked too!
44-
{ first: 10 },
45-
),
46-
})
47-
// ...
48-
}
49-
```
50-
51-
_You can find a [complete example in the repo](https://github.com/dotansimha/graphql-code-generator/tree/7c25c4eeb77f88677fd79da557b7b5326e3f3950/examples/front-end/react/tanstack-react-query)_
52-
53-
Get started with the [dedicated guide on GraphQL Code Generator documentation](https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue).
54-
55-
[//]: # 'Codegen'
Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,6 @@
11
---
22
id: background-fetching-indicators
33
title: Background Fetching Indicators
4+
ref: docs/framework/react/guides/background-fetching-indicators.md
5+
replace: { 'React': 'Preact', 'react-query': 'preact-query' }
46
---
5-
6-
A query's `status === 'pending'` state is sufficient enough to show the initial hard-loading state for a query, but sometimes you may want to display an additional indicator that a query is refetching in the background. To do this, queries also supply you with an `isFetching` boolean that you can use to show that it's in a fetching state, regardless of the state of the `status` variable:
7-
8-
[//]: # 'Example'
9-
10-
```tsx
11-
function Todos() {
12-
const {
13-
status,
14-
data: todos,
15-
error,
16-
isFetching,
17-
} = useQuery({
18-
queryKey: ['todos'],
19-
queryFn: fetchTodos,
20-
})
21-
22-
return status === 'pending' ? (
23-
<span>Loading...</span>
24-
) : status === 'error' ? (
25-
<span>Error: {error.message}</span>
26-
) : (
27-
<>
28-
{isFetching ? <div>Refreshing...</div> : null}
29-
30-
<div>
31-
{todos.map((todo) => (
32-
<Todo todo={todo} />
33-
))}
34-
</div>
35-
</>
36-
)
37-
}
38-
```
39-
40-
[//]: # 'Example'
41-
42-
## Displaying Global Background Fetching Loading State
43-
44-
In addition to individual query loading states, if you would like to show a global loading indicator when **any** queries are fetching (including in the background), you can use the `useIsFetching` hook:
45-
46-
[//]: # 'Example2'
47-
48-
```tsx
49-
import { useIsFetching } from '@tanstack/preact-query'
50-
51-
function GlobalLoadingIndicator() {
52-
const isFetching = useIsFetching()
53-
54-
return isFetching ? (
55-
<div>Queries are fetching in the background...</div>
56-
) : null
57-
}
58-
```
59-
60-
[//]: # 'Example2'
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,6 @@
11
---
22
id: caching
33
title: Caching Examples
4+
ref: docs/framework/react/guides/caching.md
5+
replace: { 'React': 'Preact', 'react-query': 'preact-query' }
46
---
5-
6-
> Please thoroughly read the [Important Defaults](./important-defaults.md) before reading this guide
7-
8-
## Basic Example
9-
10-
This caching example illustrates the story and lifecycle of:
11-
12-
- Query Instances with and without cache data
13-
- Background Refetching
14-
- Inactive Queries
15-
- Garbage Collection
16-
17-
Let's assume we are using the default `gcTime` of **5 minutes** and the default `staleTime` of `0`.
18-
19-
- A new instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` mounts.
20-
- Since no other queries have been made with the `['todos']` query key, this query will show a hard loading state and make a network request to fetch the data.
21-
- When the network request has completed, the returned data will be cached under the `['todos']` key.
22-
- The hook will mark the data as stale after the configured `staleTime` (defaults to `0`, or immediately).
23-
- A second instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` mounts elsewhere.
24-
- Since the cache already has data for the `['todos']` key from the first query, that data is immediately returned from the cache.
25-
- The new instance triggers a new network request using its query function.
26-
- Note that regardless of whether both `fetchTodos` query functions are identical or not, both queries' [`status`](../reference/useQuery.md) are updated (including `isFetching`, `isPending`, and other related values) because they have the same query key.
27-
- When the request completes successfully, the cache's data under the `['todos']` key is updated with the new data, and both instances are updated with the new data.
28-
- Both instances of the `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` query are unmounted and no longer in use.
29-
- Since there are no more active instances of this query, a garbage collection timeout is set using `gcTime` to delete and garbage collect the query (defaults to **5 minutes**).
30-
- Before the cache timeout (gcTime) has completed, another instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` mounts. The query immediately returns the available cached data while the `fetchTodos` function is being run in the background. When it completes successfully, it will populate the cache with fresh data.
31-
- The final instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` unmounts.
32-
- No more instances of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` appear within **5 minutes**.
33-
- The cached data under the `['todos']` key is deleted and garbage collected.

0 commit comments

Comments
 (0)