mirror of
https://github.com/Snigdha-OS/Snigdha-OS.github.io.git
synced 2025-09-07 13:15:17 +02:00
🚀 feat(_new): new website ui and function
This commit is contained in:
25
src/hooks/useLocation.ts
Normal file
25
src/hooks/useLocation.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getUserLocation, type UserLocation } from '@/lib/location';
|
||||
|
||||
export function useLocation() {
|
||||
const [location, setLocation] = useState<UserLocation | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchLocation() {
|
||||
try {
|
||||
const userLocation = await getUserLocation();
|
||||
setLocation(userLocation);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err : new Error('Failed to get location'));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
fetchLocation();
|
||||
}, []);
|
||||
|
||||
return { location, isLoading, error };
|
||||
}
|
Reference in New Issue
Block a user