For those of us who have been working on React apps, localhost:3000 is our constant companion when we start our Rails server on the backend. When we need data from our backend, a simple fetch from the localhost URL will usually suffice.

Image for post

However, when I start diving into React Native (using Expo), things get a bit dicy. I think everyone should be familiar with the following if you have done enough “rails s” on your terminal command line.

Image for post

IP address 127.0.0.1, localhost, is listening on port 3000 so when my JavaScript Fetch is pointing to that host name and port number, I get my JSON data back from my Rails backend app. However, a React Native app running on an iPhone via Expo doesn’t recognize localhost. From what I have read, we need to use the actual IP address instead. Since my iPhone is connected to the same WiFi network as my Macbook Pro, which runs the backend Rails app, I should be able to change my URL from “http://localhost:3000” to “http://127.0.0.1:3000”, right?

#iphone #rails #react-native #react

Connecting React Native App From iPhone To Mac
1.50 GEEK