Location Provider
A context provider for managing location data and formatting across your application.
API reference
LocationProvider
The main provider component that wraps your application to provide location functionality.
| Option | Description | Default |
|---|---|---|
children | Type: ReactNode (required)The child components that will have access to the location context. | |
coordinates | Type: Coordinates (optional)Initial coordinates to set. | |
formatter | Type: CoordinatesFormatter (optional)Custom formatter function for coordinates. | |
onChange | Type: (coordinates: Coordinates) => void (optional)Event handler called when coordinates change. | |
useLocationContext
A custom hook to access the location context within child components.
Returns an object with the following properties:
| Name | Type | Description |
|---|---|---|
coordinates | Coordinates | undefined | The current coordinates. |
formattedCoordinates | FormattedCoordinates | null | The formatted coordinates. |
coordinatesString | string | null | The coordinates as a formatted string. |
setCoordinates | (newCoordinates: Coordinates) => void | Function to update the coordinates. |
Types
Coordinates
The structure of the coordinates object.
interface Coordinates {
lat: number;
lon: number;
}FormattedCoordinates
The structure of the formatted coordinates object.
interface FormattedCoordinates {
lat: string;
lon: string;
}CoordinatesFormatter
The type for the custom formatter function.
type CoordinatesFormatter = (coordinates: Coordinates) => FormattedCoordinates;