import { useCorvexCart, useStorefront } from '@corvex/theme-sdk';
function FreeGiftsBanner() {
const storefront = useStorefront();
const { cart } = useCorvexCart();
const [gifts, setGifts] = useState([]);
useEffect(() => {
if (!cart) return;
let cancelled = false;
storefront.gifts
.eligible({
cartQuantity: cart.itemsCount ?? cart.itemCount ?? 0,
cartTotal: cart.subtotalPrice ?? cart.totalPrice ?? 0,
})
.then((connection) => {
if (!cancelled) setGifts(connection.nodes ?? []);
});
return () => {
cancelled = true;
};
}, [storefront, cart]);
if (!gifts.length) return null;
return (
<ul>
{gifts.map((gift) => (
<li key={gift.id}>{gift.name}</li>
))}
</ul>
);
}