Skip to content

Commit 101dd85

Browse files
Add location provider documentation to README
1 parent 9136903 commit 101dd85

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

readme.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,38 @@ const MyCommponent = () => {
114114
}
115115
```
116116

117+
### LocationProvider
118+
119+
This part includes a React context that fetches the geolocation at a given interval.
120+
121+
```tsx
122+
import { LocationProvider } from '@aboutbits/react-toolbox'
123+
124+
const MyApp = () => {
125+
126+
return (
127+
<LocationProvider highAccuracy={true} delay={20000}>
128+
{children}
129+
</LocationProvider>
130+
)
131+
}
132+
```
133+
134+
The context provider takes two props:
135+
- `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).
136+
- `delay`: the delay in milliseconds between each fetch
137+
138+
```tsx
139+
import { useContext } from 'react'
140+
import { LocationContext } from '@aboutbits/react-toolbox'
141+
142+
const MyComponent = () => {
143+
const { location } = useContext(LocationContext)
144+
145+
return null
146+
}
147+
```
148+
117149
## Build & Publish
118150

119151
To publish the package commit all changes and push them to main. Then run one of the following commands locally:

0 commit comments

Comments
 (0)