Connect Your Local Development Environment to React Native

Connect Your Local Development Environment to React Native

Post by: Niraj Dhungana

Posted on: Nov 11, 2021

#React Native# Expo

If you come to this post then it means you are trying to connect your React Native project with some kind of local development environment. Also it means you found that making a get or post request to localhost from you React Native doesn’t work.

Don’t worry I used to face this same problem every time while I was developing a full stack app with React Native and Node JS. React Native doesn’t like localhost out of the box. We need to do some magic to make it work.

What to Use if Not Localhost?

As I already told you, React Native doesn’t like localhost but it is also crucial for developers like us to connect our local development environment to React Native.

Instead of localhost we can use our IP address to connect our local development environment to our React Native app.

Where Do I Search For My IP Address?

Great question where do you search for your IP address. Frankly speaking I don’t know about MAC but if you are a windows user like me. Then you can simply click on the bottom right corner on the internet or wi-fi icon.

step one to get your IP to connect react native and local dev environment

Select your network. I am using LAN if you have a wi-fi connection then click on properties after clicking on your network.

step two to get your IP to connect react native and local dev environment

Now again click on the name of your network.

step three to get your IP to connect react native and local dev environment

And at the bottom of this page you will see these two IP addresses. You need the first one IPv4 address.

step four to get your IP to connect react native and local dev environment

Now you can replace your localhost with this IP address.

1
axios.get(‘http://_**your_ip**_/endpoint’)