Skip to content

🌍 usePosition: React hook for fetching and following a browser geolocation

project
306

React hook usePosition() for fetching and following a browser geolocation

  • JavaScript
  • React
  • Geolocation
  • React Hooks

About

usePosition is a React hook that gets the user's location from the browser's Geolocation API. It can fetch the position once, or keep following it and update your component whenever the location changes.

The hook returns the latitude, longitude, speed, heading, accuracy and timestamp of the position, along with any error, and accepts the standard position options: high accuracy, timeout and the maximum age of a cached position. It's published on npm, and a Storybook demo shows it in action.

Achievements

1