OfflineReactNative
Installation
npm install --save @redux-beacon/offline-react-nativeImport
import OfflineReactNative from '@redux-beacon/offline-react-native';Usage
Step 1
import { NetInfo } from 'react-native';
const initialState = {
isConnected: true, // by default the app is assumed to have a connection
}
function reducer(state = initialState, action) {
switch (action.type) {
case 'UPDATE_CONNECTIVITY' {
return Object.assign({}, state, { isConnected: action.payload });
}
...
default:
return state;
}
}
// add event listeners to update the connectivity flag when the
// connection status changes
NetInfo.isConnected.addEventListener('change', (isConnected) => {
store.dispatch({
type: 'UPDATE_CONNECTIVITY',
payload: isConnected,
});
});Step 2
Step 3
Last updated