How to add multi-currency pricing to a React app? #8
|
I'm building a SaaS product and want to show prices in the user's local currency. What's the best approach in React? AnswerUse the npm install react-currency-localizer-realtimeOption 1: Drop-in component import { LocalizedPrice } from 'react-currency-localizer-realtime';
function PricingCard() {
return (
<div>
<h3>Pro Plan</h3>
<LocalizedPrice
basePrice={19.99}
baseCurrency="USD"
apiKey="art_live_YOUR_KEY"
/>
</div>
);
}Option 2: Hook for full control import { useCurrencyConverter } from 'react-currency-localizer-realtime';
function ProductPrice({ price }) {
const { convertedPrice, localCurrency, isLoading } = useCurrencyConverter({
basePrice: price,
baseCurrency: 'USD',
apiKey: 'art_live_YOUR_KEY',
});
if (isLoading) return <span>Loading...</span>;
return (
<span>
{new Intl.NumberFormat(undefined, {
style: 'currency',
currency: localCurrency || 'USD',
}).format(convertedPrice || price)}
</span>
);
}This automatically shows a US visitor Get your free API key: allratestoday.com/register |
Replies: 3 comments
The Concern: Price MismatchUsing an external currency API causes mismatched prices. External APIs provide mid-market rates, whereas payment gateways (Stripe, PayPal, Paddle) apply their own conversion markups (1-2%). If you calculate prices on the frontend, your users will see one price but get charged a higher amount at checkout. The Solution: Gateway as Single Source of TruthTo ensure 100% accuracy, remove third-party currency switchers. Instead, let your backend query your payment gateway for the exact localized price, then serve that "ground-truth" data to React. |
|
Good callout — you're right that displaying one price and charging another is a bad UX. But the fix isn't to remove currency localization entirely. For SaaS pricing pages, there are two common patterns:
Where react-currency-localizer-realtime fits: Where you're right: TL;DR: Use a currency API for localization and detection, use your gateway for the final charge. They work together, not as replacements. |
|
Use the npm install react-currency-localizer-realtimeOption 1: Drop-in component import { LocalizedPrice } from 'react-currency-localizer-realtime';
function PricingCard() {
return (
<div>
<h3>Pro Plan</h3>
<LocalizedPrice
basePrice={19.99}
baseCurrency="USD"
apiKey="art_live_YOUR_KEY"
/>
</div>
);
}Option 2: Hook for full control import { useCurrencyConverter } from 'react-currency-localizer-realtime';
function ProductPrice({ price }) {
const { convertedPrice, localCurrency, isLoading } = useCurrencyConverter({
basePrice: price,
baseCurrency: 'USD',
apiKey: 'art_live_YOUR_KEY',
});
if (isLoading) return <span>Loading...</span>;
return (
<span>
{new Intl.NumberFormat(undefined, {
style: 'currency',
currency: localCurrency || 'USD',
}).format(convertedPrice || price)}
</span>
);
}This automatically shows a US visitor Get your free API key: allratestoday.com/register |
Use the
react-currency-localizer-realtimepackage — it auto-detects the user's currency via IP geolocation and converts prices in real time.Option 1: Drop-in component
Option 2: Hook for full control