Query Key Array not Updating with key is changed
I'm running into an issue where my query key array isn't updating when I change a selected warehouse ID in a dropdown menu. As a result,
useQuery
is using old query data instead of fetching new data for the selected warehouse ID. I'm not sure how to update the query key array when the selected warehouse ID changes, and I was wondering if you could provide any guidance on how to resolve this issue? Thank you!
I've attached a video to this message that explains the issue in more detail.
4 Replies
eager-peach•3y ago
seems like
userStore
is reactive
not ref
so accessing its properties breaks reactivity.
Either use computed
to get selectedWarehouse
or pass whole userStore
to query key depending on use casexenial-black•3y ago
use storeToRefs
rival-black•3y ago
Hey @Eduardo García Thank you for this, I just started playing around with Nuxt/vue and was running to this issue spent some time looking for this, perhaps this could be added to the docs when using pinia
eager-peach•3y ago
This isn't strictly
pinia
related. It's how Vue handles destructuring of reactive
objects.
The same thing will happen when you would access component props.
And for the same reason vue-query
by default returns refs
instead of reactive
.