OfflineWeb
Installation
npm install --save @redux-beacon/offline-webImport
import OfflineWeb from '@redux-beacon/offline-web';Usage
Step 1
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;
}
}
window.addEventListener('offline', () => {
store.dispatch({
type: 'UPDATE_CONNECTIVITY',
payload: false,
});
});
window.addEventListener('online', () => {
store.dispatch({
type: 'UPDATE_CONNECTIVITY',
payload: true,
});
});Step 2
Step 3
Last updated