UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

19 lines (18 loc) 965 B
import { useGeolocation } from '../browser-web-apis/useGeolocation'; import { useFetch } from './useFetch'; type GeolocationState = ReturnType<typeof useGeolocation>; type UseFetchReturn<T = any> = ReturnType<typeof useFetch<T>>; /** * A hook that fetches data from an API based on the user's current geolocation. * * @param urlBuilder A function that takes latitude and longitude and returns the URL string or Request object. * @param fetchOptions Options for the underlying useFetch hook (standard RequestInit). * @param geolocationOptions Options for the underlying useGeolocation hook. * @returns An object containing geolocation state and fetch state. */ export declare function useLocationBasedFetch<T = any>(urlBuilder: (latitude: number, longitude: number) => string | undefined, // Simplified builder fetchOptions?: RequestInit, geolocationOptions?: PositionOptions): { geolocation: GeolocationState; fetch: UseFetchReturn<T>; }; export {};