Refetch with params in vue #5122
Answered
by
DamianOsipiuk
Pranav-Bobde
asked this question in
Q&A
-
Then looked at #2587 and #351 and then tried to use that in stackblitz. So, instead of useState, we have refs in vue. Stackblitz Link: Questions:
|
Beta Was this translation helpful? Give feedback.
Answered by
DamianOsipiuk
Mar 14, 2023
Replies: 1 comment 1 reply
-
Two issues in this code that i can see:
const isEnabled = computed(() => payload.value.order_names.length > 0);
const { data, error, isLoading, isSuccess, refetch } = useQuery({
queryKey: ['update-order-name', order_id, payload],
queryFn: fetchOrder,
enabled: isEnabled,
onSettled: (data, error) => {
if (data) {
console.log('data: ', data);
}
if (error) {
console.log('error: ', error);
}
},
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Pranav-Bobde
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two issues in this code that i can see:
refetch
.useQuery
is smart enough to refetch automatically when you change the parameters passed toqueryKey
unwrapping
yourref
when calculatingenabled
do it viacomputed
. When you access.value
in that place, your are basically loosing reactivity, since this code is run only once. To get proper updates you should do something like this: