From 101dd857ab8babe81266909d0c2c63ac90e9ddf4 Mon Sep 17 00:00:00 2001 From: Natan Cieplinski Date: Wed, 18 Aug 2021 10:46:20 +0200 Subject: [PATCH 1/4] Add location provider documentation to README --- readme.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/readme.md b/readme.md index c2d0a44..996e3a8 100644 --- a/readme.md +++ b/readme.md @@ -114,6 +114,38 @@ 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`: define 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 null +} +``` + ## Build & Publish To publish the package commit all changes and push them to main. Then run one of the following commands locally: From e8392d13ae47d74d67941dd528a34a0835d25904 Mon Sep 17 00:00:00 2001 From: Natan Cieplinski Date: Wed, 18 Aug 2021 10:47:20 +0200 Subject: [PATCH 2/4] Fix grammar --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 996e3a8..6ecb4a4 100644 --- a/readme.md +++ b/readme.md @@ -132,7 +132,7 @@ const MyApp = () => { ``` The context provider takes two props: -- `highAccuracy`: define 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). +- `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 From 862dbb6e1e6135e85c557845b9e310020a44478e Mon Sep 17 00:00:00 2001 From: Natan Cieplinski Date: Wed, 18 Aug 2021 10:48:34 +0200 Subject: [PATCH 3/4] Update toc --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 6ecb4a4..bbdfcae 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) From f77f65e245e3e0c55a9dfed7054c6a7633844f1b Mon Sep 17 00:00:00 2001 From: Natan Cieplinski Date: Wed, 18 Aug 2021 11:02:34 +0200 Subject: [PATCH 4/4] Enrich snippet --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index bbdfcae..a65f43e 100644 --- a/readme.md +++ b/readme.md @@ -143,7 +143,9 @@ import { LocationContext } from '@aboutbits/react-toolbox' const MyComponent = () => { const { location } = useContext(LocationContext) - return null + return location + ?
Your location is: {location.coords.latitude}, {location.coords.longitude}
+ :
Unable to get your location
} ```