Skip to content

docs: Clarify that useQuery results are immutable #9108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
docs: Clarify that useQuery results are immutable
  • Loading branch information
ericyd committed May 5, 2025
commit 2b96d278a0dd553e827cfad844b28cbb38588547
7 changes: 7 additions & 0 deletions docs/framework/vue/reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,17 @@ export function useUserProjects(userId: MaybeRef<string>) {

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.
- Pass query option that accept all three types of values in Vue: refs, plain values, and reactive getters.
- 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.