DEV Community 👩‍💻👨‍💻

Moaml Riad
Moaml Riad

Posted on • Updated on

How to get the [ IP, location ...etc ] of anyone visit your site in React/JavaScript

My First Simple article at DEV Community :)

i wrote a simple [Covid-19 Tracker], when you open it will give you the information of your country accord to your location.

You can check my so simple project [Covid-19 Tracker]
Github: https://github.com/moamlrh/covid-tracker/tree/master

* NOTE : this article for absolute beginner:)

It's easy, i don't wanna waste your time.

First Of All :

we'll create a file called App.js :

App.js

Request and API

Then make get request to https://ip.nf/me.json
we'll use fetch to make request but you can use whatever you want [try with Axios]

The response will Looks like :
response

Your information => IP, Country, Country Code, City,ASN etc...

Finally,

we can use it with React Hooks [useState, useEffect]:

code

The Final result :

country name, code, city, latitude & longitude

* latitude & longitude you can use it in your project if you use map or do whatever you want

I hope you benefit from this article,
Thanks for spend some time to learn new simple things.

" LEARN & NEVER STOP "

Top comments (0)

In defense of the modern web

I expect I'll annoy everyone with this post: the anti-JavaScript crusaders, justly aghast at how much of the stuff we slather onto modern websites; the people arguing the web is a broken platform for interactive applications anyway and we should start over;

React users; the old guard with their artisanal JS and hand authored HTML; and Tom MacWright, someone I've admired from afar since I first became aware of his work on Mapbox many years ago. But I guess that's the price of having opinions.