react-hooks-bank
Version:
A collection of **powerful, reusable custom React hooks** for complex, non-trivial interactions that go beyond React’s native features.
13 lines (12 loc) • 402 B
JavaScript
import { useEffect, useState } from "react";
export function useGeolocation() {
var _a = useState(null), location = _a[0], setLocation = _a[1];
useEffect(function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
return setLocation(position.coords);
});
}
}, []);
return location;
}