UNPKG

@rooks/use-geolocation

Version:

A hook to provide the geolocation info on client side.

3 lines (2 loc) 1.02 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("tslib"),require("react")):"function"==typeof define&&define.amd?define(["tslib","react"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).useGeolocation=t(e.tslib,e.React)}(this,(function(e,t){"use strict";const o={enableHighAccuracy:!1,timeout:1/0,maximumAge:0,when:!0};return function(i=o){const[n,r]=t.useState(null),{when:s,enableHighAccuracy:a,timeout:c,maximumAge:u}=i;return t.useEffect((()=>{s&&function(){e.__awaiter(this,void 0,void 0,(function*(){try{const t=yield(e={when:s,enableHighAccuracy:a,timeout:c,maximumAge:u},new Promise(((t,o)=>{navigator.geolocation?navigator.geolocation.getCurrentPosition((e=>{const{coords:o}=e,{latitude:i,longitude:n}=o;t({lat:i,lng:n,isError:!1,message:""})}),(e=>{o({message:e.message,isError:!0})}),e):o({isError:!0,message:"Geolocation is not supported for this Browser/OS."})})));r(t)}catch(e){r(e)}var e}))}()}),[s,a,c,u]),n}})); //# sourceMappingURL=index.min.js.map