UNPKG

use-barikoi

Version:

Your favorite Barikoi APIs now available as react hooks!

53 lines 1.43 kB
import { reverseGeocode } from 'barikoi-unified'; import { useEffect, useState } from 'react'; export const useReverseGeocode = (apiKey, latitude, longitude, extraFields = { district: undefined, post_code: undefined, country: undefined, sub_district: undefined, union: undefined, pauroshova: undefined, location_type: undefined, }) => { const { district, post_code, country, sub_district, union, pauroshova, location_type, } = extraFields; const [result, setResult] = useState(); const [loading, setLoading] = useState(false); useEffect(() => { if (!latitude || !longitude) { return; } setLoading(true); reverseGeocode(apiKey, { latitude, longitude, district, post_code, country, sub_district, union, pauroshova, location_type, }) .then((res) => { setLoading(false); setResult(res); }) .catch((error) => { setLoading(false); console.error(error); }); }, [ apiKey, country, district, latitude, location_type, longitude, pauroshova, post_code, sub_district, union, ]); return [result, loading]; }; //# sourceMappingURL=use-reverse-geocode.js.map