26 lines
557 B
JavaScript
26 lines
557 B
JavaScript
import axios from 'axios'
|
|
import { useEffect, useState } from 'react'
|
|
|
|
export const useLocation = () => {
|
|
const [location, setLocation] = useState()
|
|
|
|
useEffect(() => {
|
|
async function fetchData() {
|
|
try {
|
|
const response = await axios('https://location.kremalicious.com')
|
|
if (!response) return
|
|
setLocation(response.data)
|
|
} catch (error) {
|
|
console.error(error.message)
|
|
}
|
|
}
|
|
fetchData()
|
|
}, [])
|
|
|
|
return {
|
|
now: location?.now,
|
|
next: location?.next,
|
|
previous: location?.previous
|
|
}
|
|
}
|