1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-15 17:03:26 +02:00
portfolio/src/hooks/useLocation.js
Matthias Kretschmann 5a310017b9
add location (#692)
* add current and next location

* add documentation

* api -> src/api symlink so local dev & Vercel work

* add to footer

* test changes

* styling changes

* spacing

* layout fixes
2021-10-19 21:47:19 +01:00

26 lines
537 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(`/api/location`)
if (!response) return
setLocation(response.data)
} catch (error) {
console.error(error.message)
}
}
fetchData()
}, [])
return {
now: location?.now,
next: location?.next,
previous: location?.previous
}
}