Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cristhianblaffita-web/Weather-App-Ts/llms.txt
Use this file to discover all available pages before exploring further.
useWeather is a custom React hook that retrieves live weather data from the Open-Meteo Forecast API for a given geographic location. It returns current conditions (temperature, humidity, wind speed, cloud cover, and day/night status), an hourly temperature and weather-code series, and a daily summary covering high/low temperatures, weather codes, and sunrise/sunset times. When either coordinate is null the hook is dormant — it sets loading to false and waits until valid coordinates are supplied before making any network request.
Signature
Parameters
Geographic latitude of the target location in decimal degrees. Pass
null to suspend fetching — the hook will not make any API call until a non-null value is provided.Geographic longitude of the target location in decimal degrees. Pass
null to suspend fetching — the hook will not make any API call until a non-null value is provided.Return Value
| Field | Type | Description |
|---|---|---|
weather | WeatherResponse | null | Full API response object, or null before the first successful fetch |
loading | boolean | true while the fetch is in progress |
error | string | null | Error message if the request failed, or null on success |
API Endpoint
useWeather calls the Open-Meteo Forecast API with the following URL template:
timezone=auto parameter instructs the API to return all timestamps in the local timezone of the requested location, so sunrise, sunset, and hourly times are always meaningful to the end user without any client-side conversion.
Usage Example
The following pattern is used insideWeatherContext. A useMemo call derives a stable coordinate object from the selected city so that the hook only re-fetches when the city actually changes:
useWeather places latitude and longitude in its useEffect dependency array, so it automatically re-fetches whenever either coordinate changes. Selecting a new city updates both values simultaneously, triggering a single fresh request for the new location.