Deviopath › React

Temperature Converter

Medium · State

Keep two inputs in sync: <input name="celsius"> and <input name="fahrenheit">.

Typing in one input updates the other:

- F = C * 9 / 5 + 32

- C = (F - 32) * 5 / 9

Round the converted number to 1 decimal with Math.round(x * 10) / 10 and show it as a plain number (e.g. "98.6", "0"). If the typed text is empty or not a number, the other input becomes empty.

Tip: store only one value plus which scale it was typed in, and compute the other.

Next: Loading with Retry