UNPKG

use-barikoi

Version:

Your favorite Barikoi APIs now available as react hooks!

58 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useReverseGeocode = void 0; var barikoi_unified_1 = require("barikoi-unified"); var react_1 = require("react"); var useReverseGeocode = function (apiKey, latitude, longitude, extraFields) { if (extraFields === void 0) { extraFields = { district: undefined, post_code: undefined, country: undefined, sub_district: undefined, union: undefined, pauroshova: undefined, location_type: undefined, }; } var district = extraFields.district, post_code = extraFields.post_code, country = extraFields.country, sub_district = extraFields.sub_district, union = extraFields.union, pauroshova = extraFields.pauroshova, location_type = extraFields.location_type; var _a = react_1.useState(), result = _a[0], setResult = _a[1]; var _b = react_1.useState(false), loading = _b[0], setLoading = _b[1]; react_1.useEffect(function () { if (!latitude || !longitude) { return; } setLoading(true); barikoi_unified_1.reverseGeocode(apiKey, { latitude: latitude, longitude: longitude, district: district, post_code: post_code, country: country, sub_district: sub_district, union: union, pauroshova: pauroshova, location_type: location_type, }) .then(function (res) { setLoading(false); setResult(res); }) .catch(function (error) { setLoading(false); console.error(error); }); }, [ apiKey, country, district, latitude, location_type, longitude, pauroshova, post_code, sub_district, union, ]); return [result, loading]; }; exports.useReverseGeocode = useReverseGeocode; //# sourceMappingURL=use-reverse-geocode.js.map