Lifting state up in React

React interview exercise on State, difficulty 2 of 3. Solve it in the editor beside a worked example; the tests run the moment you do.

Write TemperatureInput({ scale, value, onChange }): a label ("Celsius" or "Fahrenheit") and a controlled <input className={scale}> reporting its text. Write TemperatureConverter holding ONE value (the Celsius text) and rendering both inputs, converting for the Fahrenheit one (F = C × 9/5 + 32, two decimals at most, blank stays blank). Typing in either updates the other.

Each exercise pairs a worked example with a twin problem to solve in a real editor; the tests run the moment you do. Progress is saved in your browser, and in your account if you sign in.

More State in React

All React exercises · Other languages and frameworks