-
I am migrating to Pinia Colada and when using the enabled property, there was no change in the value as desired, see code below: const accessToken = ref(localStorage.getItem("accessToken") || "");
const getAccount = useQuery({
key: () => ["account", accessToken.value],
query: () => authService.getAccount({ token: accessToken.value }),
enabled: !!accessToken.value,
});
const loginAccountMutation = useMutation<
LoginAccountResponse,
LoginAccountProps,
Error
>({
mutation: async data => {
const response = await authService.loginAccount(data);
return response;
},
onSuccess: data => {
accessToken.value = data.token;
console.log("Account logged in successfully");
},
onMutate: () => {
mutationIsLoading.value = true;
},
onSettled: () => {
mutationIsLoading.value = false;
},
onError: error => {
mutationError.value = error;
console.error(error);
},
}); I checked and the accessToken ref is being changed as expected, but the data update never comes, the call to the API is never made. |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Dec 20, 2024
Replies: 1 comment 1 reply
-
You are passing false to enabled rather than a reactive value. Here you can just pass |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
wesleyara
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are passing false to enabled rather than a reactive value. Here you can just pass
() => !!token.value