You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It just took me a while to make my query work. The reason was it depends on the state in a Pinia store. It seems I need to convert store properties to refs before putting them into a query key. Also it seems that refs are being unwrapped automatically when accessing them from the query function parameters. Here's a code example:
conststore=useSomeStore()const{ id }=storeToRefs(store)// this is required for `useQuery`constresult=useQuery({queryKey: ['todo',id],// ^? const id: RemovableRef<number>// If I use `id.value` or `store.id` the query// doesn't refetch if the ID changes.queryFn: getTodo,})asyncfunctiongetTodo({queryKey: [,id]// ^? (parameter) id: unknown// `id` here is the raw ID, not a `Ref` anymore!}: QueryFunctionContext){returnawaitfetch(`/api/todos/${id}`)}
Unfortunately, the docs don't mention any of this. They don't tell me if Refs in general are ok to be used or even required or if plain values are fine and if so under which circumstances. Could the docs please be extended to cover those topics?
(Btw. with the current API it's very difficult to type queryKey properly. It gets boilerplatey very quickly, and the type of getTodo needs to be compatible with useQuery but the types of queryKey in getTodo and useQuery are technically different...)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
It just took me a while to make my query work. The reason was it depends on the state in a Pinia store. It seems I need to convert store properties to refs before putting them into a query key. Also it seems that refs are being unwrapped automatically when accessing them from the query function parameters. Here's a code example:
Unfortunately, the docs don't mention any of this. They don't tell me if
Ref
s in general are ok to be used or even required or if plain values are fine and if so under which circumstances. Could the docs please be extended to cover those topics?(Btw. with the current API it's very difficult to type
queryKey
properly. It gets boilerplatey very quickly, and the type ofgetTodo
needs to be compatible withuseQuery
but the types ofqueryKey
ingetTodo
anduseQuery
are technically different...)Beta Was this translation helpful? Give feedback.
All reactions