docs: Clarify that useQuery
results are immutable
#9108
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR probably feels unnecessary to the maintainers, but it caused some confusion for me and seems to come up from time to time in various discussions and issue reports, e.g.
In React, immutability is a core design choice baked into most operations. For React, immutable data should be intuitive for most developers.
In contrast, Vue treats mutability as a feature, even highlighting deep reactivity in their documentation and providing recommendations on two-way bindings with v-model. For the average Vue developer, I would wager that the default assumption is that data is mutable.
useQuery
properly annotates the data asreadonly
in TypeScript. However, the TypeScript compiler (at least as of 5.8.3) does not protect against all operations onreadonly
objects. For example, this is valid and compiles just fine:(Of course, assignment is forbidden):
In addition Vue provides a warning when immutable object mutations are attempted. However, warnings can be easy to overlook and this can lead to bugs.
Therefore, I believe being explicit about immutability is a useful contribution for the Vue framework docs.