feat(client): setup tanstack query and axios
Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
17
client/src/components/Time.tsx
Normal file
17
client/src/components/Time.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useSuspenseQuery } from '@tanstack/react-query';
|
||||
import axios from 'axios';
|
||||
|
||||
export function Time() {
|
||||
const { data: time } = useSuspenseQuery({
|
||||
queryKey: ['time'],
|
||||
queryFn: async () => axios.get<{ datetime: string }>('https://worldtimeapi.org/api/timezone/Asia/Shanghai')
|
||||
.then(res => res.data.datetime)
|
||||
.then(isoString => new Date(isoString).toLocaleTimeString()),
|
||||
});
|
||||
return (
|
||||
<p>
|
||||
Current time:
|
||||
{time}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user