refactor: resolve shopping loading issue
This commit is contained in:
@@ -22,15 +22,22 @@ const ShoppingCart = () => {
|
||||
const { formatPrice } = useCurrency();
|
||||
|
||||
const getCart = async () => {
|
||||
token = localStorage.getItem("token")
|
||||
if (token == null) {
|
||||
setCartItems([])
|
||||
} else {
|
||||
const token = localStorage.getItem("token");
|
||||
|
||||
if (!token) {
|
||||
console.log("User not logged in, setting empty cart");
|
||||
setCartItems([]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await authAxios.get("/orders/cart/");
|
||||
setCartItems(response.data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching cart:", error);
|
||||
setCartItems([]);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getCart();
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user