UNPKG

use-barikoi

Version:

Your favorite Barikoi APIs now available as react hooks!

41 lines 1.63 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useNearby = void 0; var barikoi_unified_1 = require("barikoi-unified"); var react_1 = require("react"); var useNearby = function (apiKey, latitude, longitude, types, distance, limit) { if (distance === void 0) { distance = 1; } if (limit === void 0) { limit = 5; } 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); var type = Array.isArray(types) ? { q: types } : types ? { ptype: types } : {}; barikoi_unified_1.nearby(apiKey, __assign({ latitude: latitude, longitude: longitude, distance: distance, limit: limit }, type)) .then(function (res) { setLoading(false); setResult(res); }) .catch(function (error) { setLoading(false); console.error(error); }); }, [apiKey, latitude, longitude, distance, limit, types]); return [result, loading]; }; exports.useNearby = useNearby; //# sourceMappingURL=use-nearby.js.map