Repository navigation
Replies: 3 comments 1 reply
|
I don’t think you’re supposed to directly modify data like that. We have |
|
got curious and dug into the source. in const readonlyState = readonly(state)
const object = toRefs(readonlyState)so you get normal it's on purpose since |
|
That warning is correct: Vue Query's Do not write to import { useQuery, useQueryClient } from '@tanstack/vue-query'
const queryClient = useQueryClient()
const queryKey = ['ladders'] as const
const { data: ladders, isLoading, refetch } = useQuery({
queryKey,
queryFn: () => competitionsApi.getLadders(),
initialData: [],
})
onMounted(async () => {
await refetch()
queryClient.setQueryData(queryKey, [
{
id: 1,
name: 'Ladder 1',
type: 'classic',
visibility: 'public',
},
])
})If this is only for a test, prefer mocking the query function instead of poking cache in useQuery({
queryKey: ['ladders'],
queryFn: async () => [
{ id: 1, name: 'Ladder 1', type: 'classic', visibility: 'public' },
],
})
If you need a local editable copy (a form), clone it: const draft = ref<LadderListResponse[]>([])
watch(ladders, (value) => {
draft.value = value ? structuredClone(value) : []
}, { immediate: true })Edit If this cleared the readonly error, please mark this as the accepted answer. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
I'm trying to mock some data because the type for data is Ref, but according to the warning is a redonly one?
https://vuejs.org/api/reactivity-core#readonly
Your minimal, reproducible example
Explained in description
Steps to reproduce
Explained in description
Expected behavior
Being able to modify data or change the type of it
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
vue-query
TanStack Query version
5.92.7
TypeScript version
5.9.3
Additional context
vue - 3.5.26
All reactions