Skip to content

Commit e3846cd

Browse files
committed
Refactor
1 parent 9a7cd86 commit e3846cd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

refactor/src/components/Layout/Layout.component.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ const Layout = ({ children, title }: ILayoutProps) => {
3939
// Update cart in the localStorage.
4040
const updatedCart = getFormattedCart(data);
4141

42-
if (!updatedCart) {
43-
setCart(null);
42+
/*if (!updatedCart) {
43+
return;
44+
}*/
45+
46+
47+
if (!updatedCart && !data?.cart?.contents?.nodes.length) {
48+
// Clear the localStorage if we have no remote cart
4449

50+
localStorage.removeItem('woocommerce-cart');
51+
setCart(null);
4552
return;
4653
}
54+
55+
4756
localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart));
4857

4958
// Update cart data in React Context.

0 commit comments

Comments
 (0)