Currency ConverterLoading saved progress…

Currency Converter

Two-way currency conversion keeps two amount fields synchronized through an exchange rate. Build it as a single React component with US dollars on top, euros below, and a fixed rate of 1 USD = 0.92 EUR. Typing in either field recomputes the other without creating an update loop.

Signature

Implement the default App component in App.tsx. The starter renders both inputs with 100 USD and 92 EUR but leaves their state and edit handlers incomplete:

  1. Hold both amounts. Keep usd and eur as two separate useState strings.
  2. Convert on edit. Typing in USD sets eur = usd * 0.92; typing in EUR sets usd = eur / 0.92. Round the displayed counterpart to 2 decimals.
  3. Keep one edit owner. Each input's onChange updates the field you typed in and its counterpart. Do not add one effect that mirrors USD to EUR and another that mirrors EUR to USD.
  4. Handle empties. Clearing a field (empty or non-numeric) clears the other.

Examples

  • Type 50 in USD, and EUR shows 46.00.
  • Type 92 in EUR, and USD shows 100.00.
  • Clear the USD field, and EUR goes blank.

Notes

  • Compute the counterpart inside the handler. In USD's onChange, write both usd and the derived eur. Do not set up one effect that watches usd and writes eur plus another that watches eur and writes usd — that is the loop.
  • Two state values, not one. Each input binds to its own state (usd, eur), so the cursor never jumps and only the edited field drives the other.
  • Round for display only. Call toFixed(2) on the counterpart you write; keep the field you are typing in exactly as typed.
  • Styling (dark theme, inputs, rate label) is already in styles.css; focus on the state and handlers.
WE’RE LISTENING

Help make UIReady better

Found a bug or have an idea? Tell us about it.

Up to 3 files · 5 MiB each · JPG, PNG, WebP, MP4, WebM, MP3, M4A or WAV