Packages
react
components
BuyNowButton

BuyNowButton Component

The BuyNowButton component renders a button that adds an item to the cart and redirects the customer to checkout. It must be a child of a CartProvider component.

Usage

import React from "react";
import { BuyNowButton } from "@airsoko/react";
 
const MyComponent = () => {
  return (
    <BuyNowButton
      productId="your-product-id"
      variantId="your-variant-id"
      quantity={1}
      attributes={[{ key: "attributeKey", value: "attributeValue" }]}
    >
      Buy Now
    </BuyNowButton>
  );
};
 
export default MyComponent;

Props

NameTypeDefaultDescription
quantitynumber1The item quantity. Defaults to 1.
variantIdstringThe ID of the variant.
productIdstringThe ID of the product.
attributes{ key: string; value: string; }[]An array of cart line attributes that belong to the item being added to the cart.