1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-10 19:31:03 +02:00
portfolio/src/hooks/useLocation.ts
Matthias Kretschmann 447cada700
Migrate to Next.js + TypeScript (#1038)
* next.js + typescript

* more testing

* script updates

* fixes

* favicon generation

* testing

* readme updates

* tweaks

* tweaks

* move tests

* image tweaks

* ci tweaks

* commit next-env.d.ts for ci

* migrations

* fixes

* fixes

* ci tweaks

* new animations

* project preview tweaks

* add codeclimate config

* dark mode refactor, test tweaks

* readme updates

* animation tweaks

* animate in loaded images

* test update

* update humans.txt
2022-11-15 23:14:59 +00:00

40 lines
783 B
TypeScript

import { useEffect, useState } from 'react'
export type Location = {
country: string
city: string
country_code: string
date_start: string
date_end: string
}
export type UseLocation = {
now: Location
next: Location
previous: Location
}
export const useLocation = () => {
const [location, setLocation] = useState<UseLocation>()
useEffect(() => {
async function fetchData() {
try {
const response = await fetch('https://location.kremalicious.com')
const data = await response.json()
if (!data) return
setLocation(data)
} catch (error) {
console.error(error.message)
}
}
fetchData()
}, [])
return {
now: location?.now,
next: location?.next,
previous: location?.previous
}
}