Skip to content

Commit 56c37a1

Browse files
docs: update docs with v2 changes (#192)
1 parent 24e9b75 commit 56c37a1

Some content is hidden

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

43 files changed

+942
-285
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github: DamianOsipiuk
2-
custom: paypal.me/DamianOsipiuk
2+
custom: paypal.me/DamianOsipiuk

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ For topics not covered in `vue-query` docs visit [react-query docs](https://reac
4040
# Quick Start
4141

4242
1. Install `vue-query`
43-
```bash
44-
npm install vue-query
45-
# or
46-
yarn add vue-query
47-
```
4843

49-
> If you are using Vue 2.x, make sure to also setup [@vue/composition-api](https://github.com/vuejs/composition-api)
44+
```bash
45+
npm install vue-query
46+
# or
47+
yarn add vue-query
48+
```
49+
50+
> If you are using Vue 2.x, make sure to also setup [@vue/composition-api](https://github.com/vuejs/composition-api)
5051
5152
2. Initialize **Vue Query** via **VueQueryPlugin**
5253

docs/_sidebar.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [Overview](/)
44
- [Installation](getting-started/installation.md)
5+
- [Quick Start](getting-started/quick-start.md)
56
- [DevTools](getting-started/devtools.md)
67
- [TypeScript](getting-started/typescript.md)
78

@@ -11,6 +12,7 @@
1112
- [Queries](guides/queries.md)
1213
- [Query Keys](guides/query-keys.md)
1314
- [Query Functions](guides/query-functions.md)
15+
- [Network Mode](guides/network-mode.md)
1416
- [Parallel Queries](guides/parallel-queries.md)
1517
- [Dependent Queries](guides/dependent-queries.md)
1618
- [Background Fetching Indicators](guides/background-fetching-indicators.md)
@@ -23,9 +25,21 @@
2325
- [Initial Query Data](guides/initial-query-data.md)
2426
- [Prefetching](guides/prefetching.md)
2527
- [Mutations](guides/mutations.md)
26-
- [Custom clients (experimental)](guides/custom-clients.md)
28+
- [Query Invalidation](guides/query-invalidation.md)
29+
- [Invalidation from Mutations](guides/invalidations-from-mutations.md)
30+
- [Updates from Mutation Responses](guides/updates-from-mutation-responses.md)
31+
- [Optimistic Updates](guides/optimistic-updates.md)
32+
- [Query Cancellation](guides/query-cancellation.md)
33+
- [Scroll Restoration](guides/scroll-restoration.md)
34+
- [Filters](guides/filters.md)
35+
- [Caching](guides/caching.md)
36+
- [Default Query Function](guides/default-query-function.md)
37+
- [Custom Logger](guides/custom-logger.md)
38+
- [Custom client](guides/custom-client.md)
2739
- [SSR & Nuxt.js (experimental)](guides/ssr.md)
2840
- [Best Practices](guides/best-practices.md)
41+
- [Does this replace (Vuex, Pinia, etc)?](guides/does-this-replace-client-state.md)
42+
- [Migrating to Vue Query 2](guides/migrating-to-vue-query-2.md)
2943

3044
- Examples
3145

docs/getting-started/devtools.md

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,84 +6,3 @@ When you begin your Vue Query journey, you'll want these DevTools by your side.
66

77
Vue Query will seemingly integrate with official devtools, adding custom inspector and timeline events.
88
Devtools would be treeshaken from production bundles by default.
9-
10-
# **Deprecated**: standalone devtools
11-
12-
## Import the Devtools
13-
14-
The DevTools are bundle split into the vue-query/devtools package. No need to install anything extra, just:
15-
16-
```ts
17-
import { VueQueryDevTools } from "vue-query/devtools";
18-
```
19-
20-
By default, Vue Query DevTools are not included in production bundles when `process.env.NODE_ENV === 'production'`, so you don't need to worry about excluding them during a production build.
21-
22-
---
23-
24-
## Floating Mode
25-
26-
Floating Mode will mount the DevTools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the DevTools.
27-
28-
Place the following code as high in your Vue app as you can. The closer it is to the root of the page, the better it will work!
29-
30-
```vue
31-
<script lang="ts">
32-
import { defineComponent } from "vue";
33-
import { VueQueryDevTools } from "vue-query/devtools";
34-
35-
export default defineComponent({
36-
name: "App",
37-
components: { VueQueryDevTools },
38-
});
39-
</script>
40-
41-
<template>
42-
<VueQueryDevTools />
43-
</template>
44-
```
45-
46-
### Options
47-
48-
- `initialIsOpen: Boolean`
49-
- Set this `true` if you want the dev tools to default to being open
50-
- `panelProps: PropsObject`
51-
- Use this to add props to the panel. For example, you can add `className`, `style` (merge and override default style), etc.
52-
- `closeButtonProps: PropsObject`
53-
- Use this to add props to the close button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
54-
- `toggleButtonProps: PropsObject`
55-
- Use this to add props to the toggle button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
56-
- `position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
57-
- Defaults to `bottom-left`
58-
- The position of the Vue Query logo to open and close the DevTools panel
59-
60-
---
61-
62-
## Embedded Mode
63-
64-
Embedded Mode will embed the DevTools as a regular component in your application. You can style it however you'd like after that!
65-
66-
```vue
67-
<script lang="ts">
68-
import { defineComponent } from "vue";
69-
import { VueQueryDevToolsPanel } from "vue-query/devtools";
70-
71-
export default defineComponent({
72-
name: "App",
73-
components: { VueQueryDevTools },
74-
});
75-
</script>
76-
77-
<template>
78-
<VueQueryDevToolsPanel :style="{ styles }" :className="{ className }" />
79-
</template>
80-
```
81-
82-
### Options
83-
84-
Use these options to style the dev tools.
85-
86-
- `style: StyleObject`
87-
- The standard Vue style object used to style a component with inline styles
88-
- `className: string`
89-
- The standard Vue className property used to style a component with classes

docs/getting-started/installation.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,13 @@ yarn add vue-query
1010
1111
### Vue Query Initialization
1212

13-
Before starting using Vue Query, you need to initialize it.
13+
Before starting using Vue Query, you need to initialize it using `VueQueryPlugin`
1414

15-
There are 2 possible ways to do it.
15+
```ts
16+
import { VueQueryPlugin } from "vue-query";
1617

17-
1. Using `VueQueryPlugin` (recommended)
18-
19-
```ts
20-
import { VueQueryPlugin } from "vue-query";
21-
22-
app.use(VueQueryPlugin);
23-
```
24-
25-
2. Calling `useQueryProvider` in the root component
26-
27-
```vue
28-
<script setup>
29-
import { useQueryProvider } from "vue-query";
30-
31-
useQueryProvider();
32-
</script>
33-
```
18+
app.use(VueQueryPlugin);
19+
```
3420

3521
### Use of Composition API with `<script setup>`
3622

@@ -46,7 +32,7 @@ import { defineComponent } from "vue";
4632
import { useQuery } from "vue-query";
4733
4834
function useTodosQuery() {
49-
return useQuery("todos", fetchTodoList);
35+
return useQuery(["todos"], fetchTodoList);
5036
}
5137
5238
export default defineComponent({

docs/getting-started/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ All main concepts are inherited from the main package. Please also check the [re
99

1010
### Motivation
1111

12-
Out of the box Vue does not provide optinionated way of interacting with server data. So developers end up building custom solutions that tend to end up either over-complicated, feature lacking or using global state management libraries that are not designed for this kind of usage.
12+
Out of the box, Vue applications **do not** come with an opinionated way of fetching or updating data from your components so developers end up building their own ways of fetching data. This usually means component-based state, or using more general purpose state management libraries to store and provide asynchronous data throughout their apps.
1313

1414
While most traditional state management libraries are great for working with client state, they are **not so great at working with async or server state**. This is because **server state is totally different**. For starters, server state:
1515

@@ -18,7 +18,7 @@ While most traditional state management libraries are great for working with cli
1818
- Implies shared ownership and can be changed by other people without your knowledge
1919
- Can potentially become "out of date" in your applications if you're not careful
2020

21-
Once you grasp the nature of server state in your application, even more challenges will arise as you go, for example:
21+
Once you grasp the nature of server state in your application, **even more challenges will arise** as you go, for example:
2222

2323
- Caching... (possibly the hardest thing to do in programming)
2424
- Deduping multiple requests for the same data into a single request
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
This example very briefly illustrates the 3 core concepts of Vue Query:
2+
3+
- [Queries](guides/queries)
4+
- [Mutations](guides/mutations)
5+
- [Query Invalidation](guides/query-invalidation)
6+
7+
```vue
8+
<script setup>
9+
import { useQueryClient, useQuery, useMutation } from "vue-query";
10+
11+
// Access QueryClient instance
12+
const queryClient = useQueryClient();
13+
14+
// Query
15+
const { isLoading, isError, data, error } = useQuery(["todos"], getTodos);
16+
17+
// Mutation
18+
const mutation = useMutation(postTodo, {
19+
onSuccess: () => {
20+
// Invalidate and refetch
21+
queryClient.invalidateQueries(["todos"]);
22+
},
23+
});
24+
25+
function onButtonClick() {
26+
mutation.mutate({
27+
id: Date.now(),
28+
title: "Do Laundry",
29+
});
30+
}
31+
</script>
32+
33+
<template>
34+
<span v-if="isLoading">Loading...</span>
35+
<span v-else-if="isError">Error: {{ error.message }}</span>
36+
<!-- We can assume by this point that `isSuccess === true` -->
37+
<ul v-else>
38+
<li v-for="todo in data" :key="todo.id">{{ todo.title }}</li>
39+
</ul>
40+
<button @click="onButtonClick">Add Todo</button>
41+
</template>
42+
```
43+
44+
These three concepts make up most of the core functionality of Vue Query. The next sections of the documentation will go over each of these core concepts in great detail.

docs/guides/background-fetching-indicators.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ To do this, queries also supply you with an `isFetching` boolean that you can us
66
<script setup>
77
import { useQuery } from "vue-query";
88
9-
function useTodosQuery() {
10-
return useQuery("todos", fetchTodoList);
11-
}
12-
13-
const { isLoading, isError, data, error, isFetching } = useTodosQuery();
9+
const { isLoading, isError, data, error, isFetching } = useQuery(
10+
["todos"],
11+
fetchTodoList
12+
);
1413
</script>
1514
1615
<template>
1716
<span v-if="isLoading">Loading...</span>
1817
<span v-else-if="isError">Error: {{ error.message }}</span>
19-
<div v-else>
18+
<div v-else-if="data">
2019
<span v-if="isFetching">Refreshing...</span>
2120
<ul>
2221
<li v-for="todo in data" :key="todo.id">{{ todo.title }}</li>

docs/guides/caching.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
> ! Please thoroughly read the [Important Defaults](guides/important-defaults) before reading this guide
2+
3+
### Basic Example
4+
5+
This caching example illustrates the story and lifecycle of:
6+
7+
- Query Instances with and without cache data
8+
- Background Refetching
9+
- Inactive Queries
10+
- Garbage Collection
11+
12+
Let's assume we are using the default `cacheTime` of **5 minutes** and the default `staleTime` of **0**.
13+
14+
- A new instance of `useQuery(['todos'], fetchTodos)` mounts.
15+
- 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.
16+
- When the network request has completed, the returned data will be cached under the `['todos']` key.
17+
- The hook will mark the data as stale after the configured `staleTime` (defaults to **0**, or immediately).
18+
- A second instance of `useQuery(['todos'], fetchTodos)` mounts elsewhere.
19+
- Since the cache already has data for the `['todos']` key from the first query, that data is immediately returned from the cache.
20+
- The new instance triggers a new network request using its query function.
21+
Note that regardless of whether both `fetchTodos` query functions are identical or not, both queries' `status` are updated (including `isFetching`, `isLoading`, and other related values) because they have the same query key.
22+
- 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.
23+
- Both instances of the `useQuery(['todos'], fetchTodos)` query are unmounted and no longer in use.
24+
- Since there are no more active instances of this query, a cache timeout is set using `cacheTime` to delete and garbage collect the query (defaults to **5 minutes**).
25+
- Before the cache timeout has completed, another instance of `useQuery(['todos'], 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.
26+
- The final instance of `useQuery(['todos'], fetchTodos)` unmounts.
27+
- No more instances of `useQuery(['todos'], fetchTodos)` appear within **5 minutes**.
28+
- The cached data under the `['todos']` key is deleted and garbage collected.

docs/guides/custom-clients.md renamed to docs/guides/custom-client.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ const vueQueryPluginOptions: VueQueryPluginOptions = {
2525
app.use(VueQueryPlugin, vueQueryPluginOptions);
2626
```
2727

28-
### Custom context keys
28+
### Custom context key
2929

30-
You can also customize the key under which `QueryClient` will be accessible in Vue context. This can be usefull is you want to avoid name clashing between multiple apps on the same page.
30+
You can also customize the key under which `QueryClient` will be accessible in Vue context. This can be usefull is you want to avoid name clashing between multiple apps on the same page with Vue2.
3131

3232
It works both with default, and custom `QueryClient`
3333

@@ -53,14 +53,6 @@ To use the custom client key, You have to provide it as a query options
5353
useQuery("query1", fetcher, { queryClientKey: "foo" });
5454
```
5555

56-
Devtools also support this by the `queryClientKeys` prop. You can provide multiple keys and switch between them to monitor multiple clients.
57-
58-
```vue
59-
<template>
60-
<VueQueryDevTools :queryClientKeys="['foo', 'bar']" />
61-
</template>
62-
```
63-
6456
Internally custom key will be combined with default query key as a suffix. But user do not have to worry about it.
6557

6658
```ts

0 commit comments

Comments
 (0)