Providers
Location Provider

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.

OptionDescriptionDefault
childrenType: ReactNode (required)The child components that will have access to the location context.
coordinatesType: Coordinates (optional)Initial coordinates to set.
formatterType: CoordinatesFormatter (optional)Custom formatter function for coordinates.

useLocationContext

A custom hook to access the location context within child components.

Returns an object with the following properties:

NameTypeDescription
coordinatesCoordinates | undefinedThe current coordinates.
formattedCoordinatesFormattedCoordinates | nullThe formatted coordinates.
coordinatesStringstring | nullThe coordinates as a formatted string.
setCoordinates(newCoordinates: Coordinates) => voidFunction 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;