I am migrating the logout functionality of my hybrid app from native to react native.
Requirements:
Initially, we planned to do something like this: how-to-reset-the-state-of-a-redux-store
As of React Native 0.62.0, we now have access to the DevSettings module. DevSettings has a native bridge that can reload the react-native environment. But are DevSettings really only for development environments?
Export the DevSettings module, add addMenuItem method (cc068b0551 by @janicduplessis)
Here's the line in code that disallows using devSettings in prod
import NativeDevSettings from '../NativeModules/specs/NativeDevSettings';
import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
class DevSettings extends NativeEventEmitter {
...
reload(reason: string) {
if (typeof NativeDevSettings.reloadWithReason === 'function') {
NativeDevSettings.reloadWithReason(reason || 'Uncategorized from JS');
} else {
NativeDevSettings.reload();
}
}
...
}
// Avoid including the full `NativeDevSettings` class in prod.
class NoopDevSettings {
addMenuItem(title: string, handler: () => mixed) {}
reload() {}
}
module.exports = __DEV__ ? new DevSettings() : new NoopDevSettings();