computeVariantPrice
This utility function can be used to compute the price of a variant for a region and retrieve the amount without formatting.
For example, 20
. This method is used by formatVariantPrice before applying the price formatting.
Example
src/Products.ts
import React from "react"
import { computeVariantPrice } from "medusa-react"
import { Product, ProductVariant } from "@medusajs/medusa"
const Products = () => {
// ...
return (
<ul>
{products?.map((product: Product) => (
<li key={product.id}>
{product.title}
<ul>
{product.variants.map((variant: ProductVariant) => (
<li key={variant.id}>
{computeVariantPrice({
variant,
region, // should be retrieved earlier
})}
</li>
))}
</ul>
</li>
))}
</ul>
)
}
Parameters
Options to compute the variant's price.
Returns
number
numberRequiredThe computed price of the variant.
Was this section helpful?