Skip to content

Commit 8e4f1f2

Browse files
committed
chore: improve readme and fix test deps
1 parent d7258d0 commit 8e4f1f2

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

README.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ yarn i @hebilicious/vue-query-nuxt @tanstack/vue-query
3737
```ts
3838
// In nuxt.config.ts
3939
export default defineNuxtConfig({
40-
modules: ["@hebilicious/vue-query-nuxt"],
41-
// These are the default values, you do not need to specify them.
42-
// Refer to the vue-query docs for more information.
43-
vueQuery: {
44-
stateKey: "vue-query-nuxt",
45-
queryClientOptions: {
46-
defaultOptions: { queries: { staleTime: 5000 } } // default
47-
},
48-
vueQueryPluginOptions: {}
49-
}
40+
modules: ["@hebilicious/vue-query-nuxt"]
5041
})
5142
```
5243

@@ -59,26 +50,23 @@ import { useQueryClient, useQuery, useMutation } from '@tanstack/vue-query'
5950
// Access QueryClient instance
6051
const queryClient = useQueryClient()
6152
62-
// Define a fetching function
63-
const getTodos = () => $fetch("/api/todos")
64-
6553
// Query
6654
const { isLoading, isError, data, error } = useQuery({
6755
queryKey: ['todos'],
68-
queryFn: getTodos,
56+
queryFn: () => $fetch("/api/todos"), // Use $fetch with your api routes to get typesafety
6957
})
7058
7159
// Mutation
72-
const mutation = useMutation({
73-
mutationFn: postTodo,
60+
const { mutate } = useMutation({
61+
mutationFn: (newTodo) => $fetch("/api/todos", { method: "POST", body: newTodo })
7462
onSuccess: () => {
7563
// Invalidate and refetch
7664
queryClient.invalidateQueries({ queryKey: ['todos'] })
7765
},
7866
})
7967
8068
function onButtonClick() {
81-
mutation.mutate({
69+
mutate({
8270
id: Date.now(),
8371
title: 'Do Laundry',
8472
})
@@ -98,7 +86,23 @@ function onButtonClick() {
9886

9987
4. Advanced configuration
10088

101-
Create a `vue-query.config.ts` file at the root of your project.
89+
You can specify the options under the vueQuery key in your nuxt.config.ts file.
90+
Everything is typed.
91+
92+
```ts
93+
// In nuxt.config.ts
94+
export default defineNuxtConfig({
95+
modules: ["@hebilicious/vue-query-nuxt"],
96+
vueQuery: {
97+
stateKey: "vue-query-nuxt",
98+
queryClientOptions: {
99+
defaultOptions: { queries: { staleTime: 5000 } } // default
100+
},
101+
vueQueryPluginOptions: {}
102+
}
103+
})
104+
```
105+
If you need to modify the plugin that installs vue query, you can create a `vue-query.config.ts` file at the root of your project.
102106

103107
```ts
104108
// vue-query.config.ts
@@ -110,8 +114,8 @@ export default defineVueQueryPluginCallback((vueQueryOptions) => {
110114
})
111115
```
112116

113-
This callback will be run *directly* after the Vue Query plugin is installed, so you can use it to provide something here.
114-
This can be useful if you want to configure something that needs the queryClient or you want to provide a library.
117+
This callback will be run *directly* after the Vue Query plugin is installed, so you can use it to `provide` something.
118+
This can be useful if you want to configure something that needs the `queryClient` or you want to provide a library in the same plugin.
115119

116120
## 📦 Contributing
117121

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ packages:
22
- docs/**
33
- packages/**
44
- playgrounds/**
5+
- test/**

test/fixtures/todos/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoisted=true

test/fixtures/todos/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"private": true,
44
"dependencies": {
55
"@tanstack/vue-query": "latest",
6-
"nuxt": "latest"
6+
"nuxt": "3.5.2"
77
}
88
}

0 commit comments

Comments
 (0)