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.
useGeocoding is a custom React hook that queries the Open-Meteo Geocoding API with a city name string and returns up to ten matching Place results, each containing the city’s coordinates, country, and country code. The hook fires a new request on every change to the city argument — debouncing is the caller’s responsibility and is typically handled upstream (for example, with a 300 ms useDebounce wrapper) to avoid hammering the API on every keystroke.
Signature
Parameters
The city name search term to pass to the geocoding API. An empty string still triggers a fetch, so callers should guard against empty or very short inputs before invoking the hook — see the tip below.
Return Value
| Field | Type | Description |
|---|---|---|
cities | GeocodingResponse | null | Search results containing up to 10 matching cities, or null before the first fetch |
loading | boolean | true while the fetch is in progress |
error | string | null | Error message on failure, or null on success |
API Endpoint
useGeocoding calls the Open-Meteo Geocoding API with the following URL template:
count=10 parameter caps results at ten entries, and language=en ensures that place name variants are returned in English.
GeocodingResponse Shape
The hook types its response using the following structures:Place in results provides the latitude and longitude values that are passed directly to useWeather once the user selects a city from the search dropdown.
Usage in WeatherContext
InWeatherContext, the raw search string is debounced for 300 ms before being forwarded to useGeocoding. This prevents a new API call from firing on every keystroke while the user is still typing: