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 Loacalhost
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 wf-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.