Hooks
The hooks of @poltura/theme-sdk/price.
On this page
import { … } from '@poltura/theme-sdk/price';usePrice
The amounts behind a price, for code that must compute with them.
usePrice(price: PriceView | null): ResolvedPrice | nullParameters
price: PriceView | null: The price of a product, variant or card.
Returns: The resolved amounts, or null on pages with live prices (islands) and for hidden prices.
Example
import { usePrice } from '@poltura/theme-sdk/price';
import type { PriceView } from '@poltura/theme-sdk/price';
export function OnSale({ price }: { price: PriceView }) {
const resolved = usePrice(price);
return resolved?.compareAt ? <span>Sale</span> : null;
}usePriceAccess
Whether the visitor may see prices, on which tax basis, and what unlocks them when hidden.
usePriceAccess(): PriceAccessReturns: The visitor's price access.
Example
import type { ReactNode } from 'react';
import { PriceGate, usePriceAccess } from '@poltura/theme-sdk/price';
export function PricesOrGate({ children }: { children: ReactNode }) {
const access = usePriceAccess();
return access.visible ? <>{children}</> : <PriceGate />;
}