Find IP Location - React Native

ipapi ~ ipapi.co
1 min readFeb 14, 2020

--

With live examples on Codepen

We are adding an example of React Native + fetch API to get the location of an IP address. The fetch API is similar to XMLHttpRequest, used for Ajax methods. Here’s a simple example that makes a request to ipapi :

fetch('https://ipapi.co/json/');

The method makes it very easy to populate location data in your website or app asynchronously. We’ll expand the example by adding the capability to handle the response received by the above request :

fetch(‘https://ipapi.co/json/')
.then(response => response.json())
.then(data =>
this.setState({
location: data,
isLoading: false,
})
)

Once we receive the JSON response, the next step is to render it. Here’s a working example on Codepen to play around with :

https://codepen.io/ipapi/pen/oNXbpwO

Codepen — IP Address Location in React Native
Github Gist — IP Location using Fetch API in React Native

--

--

ipapi ~ ipapi.co

IP Lookup | IP Geolocation API | IP Address Locator by Kloudend, Inc. USA. Trusted by Fortune 500 !