I've this hook:
import axios from "axios";
import { useQuery } from "react-query";
const fetchCartPreview = (cartId, userId) => {
console.log("Init query");
axios
.get(
`${process.env.REACT_APP_API_BASE_URL}/carts/${cartId}/checkout_preview`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
params: { user_id: userId },
}
)
.then((response) => console.log("Response from hook", response.data));
};
export default function useCartPreview(cartId, userId) {
return useQuery(
["cart_preview", cartId, userId],
async () => {
const data = await fetchCartPreview(cartId, userId)
return data
},
{ onSuccess: console.log("Finish query") }
);
}
The console.log(response.data) it's ok, the problem is that the useQuery, onSuccess, returns data: undefined and T don't know why..
Console.log in the component that calls the hook
Thank you!
fetchCartPreview(), thereforedatawill beundefined