{children} @@ -69,11 +68,9 @@ export function Layout({ function Header({ title, menu, - cart, }: { title: string; menu?: EnhancedMenu; - cart?: Promise; }) { const { pathname } = useLocation(); @@ -96,7 +93,7 @@ function Header({ return ( <> - + {menu && ( )} @@ -106,7 +103,6 @@ function Header({ title={title} menu={menu} openCart={openCart} - cart={cart} /> ); @@ -176,12 +171,11 @@ function Footer({ function CartDrawer({ isOpen, onClose, - cart, }: { isOpen: boolean; onClose: () => void; - cart?: Promise; }) { + const cart = useCart(); /** * Whenever a component that uses a fetcher is _unmounted_, that fetcher is removed * from the internal Remix cache. By defining the fetcher outside of the component, @@ -195,26 +189,20 @@ function CartDrawer({ * drawer is opened. */ useEffect(() => { - topProductsFetcher.load("/cart"); + isOpen && topProductsFetcher.load("/cart"); // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [isOpen]); return (
{cart ? ( - Loading...
}> - - {(cart) => ( - - )} - - + ) : ( void; openMenu: () => void; - cart?: Promise; }) { const { y } = useWindowScroll(); @@ -336,13 +322,7 @@ function MobileHeader({