Find IP Location - React Native
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