import { useCallback, useEffect } from 'react' import {useAuthorizedContext} from '../page' export const useSendLocation = (shouldSend?: boolean, interval = 60000) => { const {requestLocation, state} = useAuthorizedContext() const sendLocation = useCallback(() => { requestLocation(state.usingZip, state.currentZip || '').catch(e => { console.error(e) }) }, [requestLocation, state]) useEffect(() => { if (!shouldSend) return const i = setInterval(sendLocation, interval) return () => clearInterval(i) }, [shouldSend, sendLocation, interval]) return {sendLocation} }