use-barikoi
Version:
Your favorite Barikoi APIs now available as react hooks!
24 lines • 909 B
JavaScript
import { nearby } from 'barikoi-unified';
import { useEffect, useState } from 'react';
export const useNearby = (apiKey, latitude, longitude, types, distance = 1, limit = 5) => {
const [result, setResult] = useState();
const [loading, setLoading] = useState(false);
useEffect(() => {
if (!latitude || !longitude) {
return;
}
setLoading(true);
const type = Array.isArray(types) ? { q: types } : types ? { ptype: types } : {};
nearby(apiKey, Object.assign({ latitude, longitude, distance, limit }, type))
.then((res) => {
setLoading(false);
setResult(res);
})
.catch((error) => {
setLoading(false);
console.error(error);
});
}, [apiKey, latitude, longitude, distance, limit, types]);
return [result, loading];
};
//# sourceMappingURL=use-nearby.js.map