Skip to content

Commit b1131ff

Browse files
authored
Merge pull request #2745 from 9M6/docs/tanstack-query-reactivity
docs: add reactivity section to TanStack Query plugin documentation
2 parents 617f3a3 + 5d06dbd commit b1131ff

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.changeset/cute-jokes-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@docs/openapi-ts': patch
3+
---
4+
5+
chore: clarify TanStack Query reactivity in Vue

docs/openapi-ts/plugins/tanstack-query.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,38 @@ export default {
574574

575575
:::
576576

577+
## Reactivity
578+
579+
In Vue applications, you need to wrap the options functions in [`computed()`](https://vuejs.org/guide/essentials/computed) to make them reactive. Otherwise, TanStack Query won't know it should execute the query when its dependencies change.
580+
581+
::: code-group
582+
583+
```js [reactive]
584+
// ✅ Query will execute on `petId` change
585+
const query = useQuery(
586+
computed(() =>
587+
getPetByIdOptions({
588+
path: {
589+
petId: petId.value,
590+
},
591+
}),
592+
),
593+
);
594+
```
595+
596+
```js [static]
597+
// ❌ Query will execute only once
598+
const query = useQuery(
599+
getPetByIdOptions({
600+
path: {
601+
petId: petId.value,
602+
},
603+
}),
604+
);
605+
```
606+
607+
:::
608+
577609
## API
578610

579611
You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@tanstack/react-query/types.d.ts) interface.

0 commit comments

Comments
 (0)