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.
Select your network. I am using LAN if you have a wi-fi connection then click on properties after clicking on your network.
Now again click on the name of your network.
And at the bottom of this page you will see these two IP addresses. You need the first one IPv4 address.
Now you can replace your localhost with this IP address.
1
axios.get(‘http://_**your_ip**_/endpoint’)
Related Posts
- React Native Multi Select on Long Press - Touchable Opacity.
- How to Setup react-native-cli and Android Emulator on Windows
- How to Compress or Manipulate Images in React Native Expo
- RecyclerListView – React Native Everything You Need to Know
- React Native Android Emulator - "could not compile settings file"