How to make React app preview on mobile?

Home / reactjs / How to make React app preview on mobile?

Question:
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?


Answer:
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 ipconfig. 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/
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *