From 2b96d278a0dd553e827cfad844b28cbb38588547 Mon Sep 17 00:00:00 2001 From: Eric Dauenhauer Date: Mon, 5 May 2025 16:53:56 -0500 Subject: [PATCH] docs: Clarify that `useQuery` results are immutable --- docs/framework/vue/reactivity.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/framework/vue/reactivity.md b/docs/framework/vue/reactivity.md index 371b32c52c..50e5b8874f 100644 --- a/docs/framework/vue/reactivity.md +++ b/docs/framework/vue/reactivity.md @@ -157,6 +157,12 @@ export function useUserProjects(userId: MaybeRef) { More details on this option can be found on the [useQuery reference](./reference/useQuery.md) page. +## Immutability + +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. + +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. + # Key Takeaways - `enabled` and `queryKey` are the two query options that can accept reactive values. @@ -164,3 +170,4 @@ More details on this option can be found on the [useQuery reference](./reference - 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) - If you don't need a query to be reactive pass in a plain value. - For trivial derived state such as property access consider using a reactive getter in place of a `computed`. +- Results from `useQuery` are always immutable.