"use client"; import { useState, useEffect } from 'react'; import { getLocationFromIP } from '@/app/utils/ipLocation'; interface LocationData { ip: string; country_name: string; country_code: string; city: string; region: string; continent_code: string; continent_name: string; latitude: number; longitude: number; } export default function IpLocationTest() { const [locationData, setLocationData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const testIp = "120.244.39.90"; useEffect(() => { async function fetchLocation() { try { setLoading(true); setError(null); const data = await getLocationFromIP(testIp); setLocationData(data); } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error occurred'); } finally { setLoading(false); } } fetchLocation(); }, []); return (

IP Location Test: {testIp}

{loading && (
Loading location data...
)} {error && (
Error: {error}
)} {!loading && locationData && (

Location Data:

              {JSON.stringify(locationData, null, 2)}
            

Country

{locationData.country_name} ({locationData.country_code})

City

{locationData.city || 'N/A'}

Region

{locationData.region || 'N/A'}

Continent

{locationData.continent_name} ({locationData.continent_code})

Coordinates

Latitude: {locationData.latitude}, Longitude: {locationData.longitude}
)}
); }