1import { useGeolocation } from 'react-modern-hooks'23const Demo = () => {4 const {5 loading,6 error,7 userIP,8 city,9 country,10 latitude,11 longitude,12 region,13 location //Object that comes with other properties on top14 } = useGeolocation()1516 if (error) {17 console.log('Error: ', error)18 }1920 if (loading) return <p>Loading...</p>2122 return (23 <div>24 <p>User IP Address: {userIP}</p>25 <p>City: {city}</p>26 <p>Country: {country}</p>27 <p>Region: {region}</p>28 <p>Longitude: {longitude}</p>29 <p>Latitude: {latitude}</p>30 <p>Location Timezone: {location?.timezone}</p>31 </div>32 )33}3435export default Demo
No input variables
location - Location object with all other user details
latitude - Current latitude of a user/agent's position
longitude - Current longitude of a user/agent's position
userIP - Current IP address of a user/agent
city - City the user/agent is currently located in
region - Region the user/agent is currently located in
country - Country the user/agent is currently located in
error - Any error occurring during geolocating a user/agent
loading - A boolean variable indicating if a users location is still being fetched