CodingNic

Units & Preferences

Convert Temperature Values

Units & Preferences 10 min read

Convert Temperature Values

Task

Make the current temperature, feels-like value, and forecast follow the selected unit.

File / section

src/components/CurrentWeather.jsx and src/components/Forecast.jsx

Change

Use const unitLabel = unit === "metric" ? "C" : "F" and round the API values. Keep the API request units parameter aligned with the selected unit.

Why this change matters

OpenWeather converts the response values when you request metric or imperial units, so the display should use the matching label.

Test it

Toggle units after a successful search and confirm temperatures change and labels switch between °C and °F.

Checkpoint

Temperature displays follow the selected unit.