Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make React app preview on mobile?

I am a noob using create-react-app to create a App, yarn start start the server at http://localhost:3000/, I can't visit this url on my mobile. How can I make some configs to preview the app on my mobile?

like image 980
Liuuil Avatar asked Aug 18 '17 15:08

Liuuil


People also ask

Can React run on mobile?

React Native is a mobile framework that compiles to native app components, allowing you to build native mobile applications, iOS, Android, and Windows, in JavaScript that allows you to use React JS to build your components, and implements ReactJS under the hood. Both are open sourced by Facebook.

Does React app work on Android?

React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces. Use a little—or a lot. You can use React Native today in your existing Android and iOS projects or you can create a whole new app from scratch.


2 Answers

First, remember you can open a mobile view in a desktop browser (at least in Chrome and Firefox). See the article for more. It isn't a substitute of testing on a real mobile device but can help you identify more obvious issues.

Second, you need to use the IP address of your computer in your local network (assuming your mobile device is on the same network as your desktop). On Linux and Mac you can check your IP with ifconfig or using ipconfig on Windows. localhost always refers to the current machine, i.e. localhost on your desktop points to your desktop and on your mobile device it points to your mobile device. That's why you can't access it - the app runs on your desktop not mobile.

Once you know the IP address of your computer you need to replace localhost with it. In my case the IP is 192.168.1.10 so I use the following address to access my app:

http://192.168.1.10:3000/ 
like image 188
Greg Navis Avatar answered Sep 29 '22 21:09

Greg Navis


All answers are correct, except two points that are forgotten:

  1. your network must be Private: on windows10, click on the wifi icon, then click on the network name, you'll see properties option, click on it, then on the network profile section, set it to Private

  2. you might not be able to connect through the ip that npm run start writes in the cmd, try your other ip addresses too. as other friends mentioned, open cmd, type in: ipconfig and press Enter, then you'll see 3 parts that all have one line with: IPv4 Address, try all these ip addresses with the port number of your react application, i hope it helps

like image 24
Mahdieh Shavandi Avatar answered Sep 29 '22 19:09

Mahdieh Shavandi