diff --git a/readme.md b/readme.md index c2d0a44..a65f43e 100644 --- a/readme.md +++ b/readme.md @@ -11,6 +11,7 @@ This package includes different tools that support you with common tasks. - [Usage](#usage) - [useInterval](#useinterval) - [Async Data](#async-data) + - [LocationProvider](#locationprovider) - [Build & Publish](#build--publish) - [Information](#information) @@ -114,6 +115,40 @@ const MyCommponent = () => { } ``` +### LocationProvider + +This part includes a React context that fetches the geolocation at a given interval. + +```tsx +import { LocationProvider } from '@aboutbits/react-toolbox' + +const MyApp = () => { + + return ( + + {children} + + ) +} +``` + +The context provider takes two props: +- `highAccuracy`: defines if the location should be fetched with high accuracy. Read more on the [Geolocation API doc](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API). +- `delay`: the delay in milliseconds between each fetch + +```tsx +import { useContext } from 'react' +import { LocationContext } from '@aboutbits/react-toolbox' + +const MyComponent = () => { + const { location } = useContext(LocationContext) + + return location + ?
Your location is: {location.coords.latitude}, {location.coords.longitude}
+ :
Unable to get your location
+} +``` + ## Build & Publish To publish the package commit all changes and push them to main. Then run one of the following commands locally: