Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging react native application in offline mode

I'm trying to add some offline support for my app, but debugging the app with my emulator in airplane mode seems to be a giant pain. Every time I reload the app without a connection I am met with this:

enter image description here

So, in essence, I would like to have the app think it does not have a connection, but maintain the connection to my development server. Is that possible?

like image 642
Juuso Avatar asked Feb 20 '17 12:02

Juuso


People also ask

Can React Native app work offline?

First, you need to check to internet connection, to make sure the device is online or offline. For this, you can use this library @react-native-community/netinfo. Second, you need to store the question and answer on redux, so when the device is offline, you can load the question from redux.

How do you handle offline in React Native?

The most popular methods to achieve offline support in React Native are by implementing usage restrictions, caching, and request queuing.

How do I run React Native apps in debug mode?

In App Developer Menu On Android emulator, you need to press command + M. Debug JS Remotely − Used for activating debugging inside browser developer console. Enable Live Reload − Used for enabling live reloading whenever your code is saved. The debugger will open at localhost:8081/debugger-ui.


Video Answer


1 Answers

The problem is 10.0.3.2 is being provided by your router so when you are on offline (or without connection), who is going to route that ip?

One option to solve this problem is to use localhost or 127.0.0.1 as Debug Server.

Other option could be adding in your host (c:\C:\Windows\System32\drivers\etc) a traduction for your IP, something like this:

10.0.3.2   127.0.0.1

Of course you have to change your devs settings in your emulator

like image 68
Facundo La Rocca Avatar answered Oct 06 '22 19:10

Facundo La Rocca