Menu

1 / 2

How to Localize Prices in React Using Exchange Rates

DEV Community·ApogeoAPI·7 months ago
#070RaP1g
#react#exchangerates#tutorial#currency#rate
Reading 0:00
15s threshold

Showing prices in a user's local currency increases trust, reduces bounce rates, and improves conversions — especially for international audiences. Here's how to do it automatically in React.

The Goal

Detect the user's currency from their IP address (no user input needed)

Fetch the live exchange rate for that currency

Format the price according to their locale

Step 1: Detect User Currency from IP

// hooks/useCurrency.ts import { useEffect , useState } from ' react ' ; export function useCurrency () { const [ currency , setCurrency ] = useState ( ' USD ' ); useEffect (() => { fetch ( ' https://api.apogeoapi.com/v1/geolocate/auto ' , { headers : { ' X-API-Key ' : process . env . NEXT_PUBLIC_APOGEO_KEY ! }, }) . then ( r => r . json ()) . then ( geo => setCurrency ( geo . currency ?? ' USD ' )) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.