medusa-gift-wrap-logic
v1.0.0
Published
Reusable gift-wrap hook and service for Medusa storefronts. Manages per-line-item gift metadata (is_gift, gift_from, gift_to, gift_message) without any UI dependencies.
Downloads
25
Maintainers
Readme
Medusa Gift Wrap Logic
A reusable gift-wrap hook and service for Medusa storefronts. This package provides the logic necessary to manage per-line-item gift metadata without any UI dependencies.
Features
- Per-Line-Item Gift Metadata: Easily apply gift metadata (
is_gift,gift_from,gift_to,gift_message) directly to line items in the cart. - Headless & UI Agnostic: Contains only the business logic and hooks. You can build your own UI components using these hooks.
- Medusa Compatible: Works seamlessly with
@medusajs/js-sdkand@medusajs/types. - TypeScript Ready: Written in TypeScript and provides complete type definitions.
Installation
npm install medusa-gift-wrap-logicSetup
First, make sure you have the required peer dependencies installed in your project:
npm install react react-domBasic Usage
The package exports a custom React hook that you can use in your React storefront or Next.js app to handle gift-wrapping logic for any product inside the cart.
import { useGiftWrap } from 'medusa-gift-wrap-logic';
export default function GiftWrapComponent({ lineItemId }) {
const { isGift, setGiftInfo, updateLineItem, isUpdating } = useGiftWrap(lineItemId);
// Implementation of your UI based on the state returned from the hook
}Development
npm run dev- Starts Vite development servernpm run build- Builds the package using TypeScript and Vitenpm run preview- Previews the build
Requirements
react18 or 19@medusajs/js-sdkv2+
