Skip to content

Commit 127bd01

Browse files
authored
docs: Clarify that useQuery results are immutable (#9108)
1 parent 8d02784 commit 127bd01

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/framework/vue/reactivity.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,17 @@ export function useUserProjects(userId: MaybeRef<string>) {
157157

158158
More details on this option can be found on the [useQuery reference](./reference/useQuery.md) page.
159159

160+
## Immutability
161+
162+
Results from `useQuery` are always immutable. This is necessary for performance and caching purposes. If you need to mutate a value returned from `useQuery`, you must create a copy of the data.
163+
164+
One implication of this design is that passing values from `useQuery` to a two-way binding such as `v-model` will not work. You must create a mutable copy of the data before attempting to update it in place.
165+
160166
# Key Takeaways
161167

162168
- `enabled` and `queryKey` are the two query options that can accept reactive values.
163169
- Pass query option that accept all three types of values in Vue: refs, plain values, and reactive getters.
164170
- If you expect a query to react to changes based on the values it consumes, ensure that the values are reactive. (i.e. pass in refs directly to the query, or use reactive getters)
165171
- If you don't need a query to be reactive pass in a plain value.
166172
- For trivial derived state such as property access consider using a reactive getter in place of a `computed`.
173+
- Results from `useQuery` are always immutable.

0 commit comments

Comments
 (0)