CodingNic

Live and Historical Data

Publish the Current Rate

Live and Historical Data 25 min read

Publish the Current Rate

Publish the Current Rate

The page also needs the selected pair’s current rate for the statistics and chart.

Create an onRateChange callback from app/page.js and call it from the converter when the computed rate changes.

javascript
useEffect(() => {
  onRateChange?.(rate);
}, [rate, onRateChange]);

Test it

Change the pair and watch the Rate statistic update.

Checkpoint

The current selected-pair rate has one source of truth and can be reused by multiple UI sections.