Skip to content

Instantly share code, notes, and snippets.

View emanueleDiVizio's full-sized avatar

Emanuele emanueleDiVizio

View GitHub Profile
@emanueleDiVizio
emanueleDiVizio / cloudSettings
Last active November 2, 2020 14:57
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-09-22T05:57:00.646Z","extensionVersion":"v3.4.3"}
const productReducer = (state, action) => {
switch (action.type) {
case offlineActionTypes.FETCH_OFFLINE_MODE:
if (
action.payload.prevAction.type ===
actionTypes.FETCH_USER_SELECTED_PRODUCT_REQUEST
) {
return handleSelectedProductWhileOffline(state, action.payload);
}
return state;
const action = {
type: 'FETCH_USER_SELECTED_PRODUCT_REQUEST',
payload: {
id: 2
},
meta: {
retry: true
}
};
type ActionToBeQueued = {
type: string,
payload?: any,
meta: {
retry?: boolean, // By passing true, your action will be enqueued on offline mode
dismiss?: Array<string> // Array of actions which, once dispatched, will trigger a dismissal from the queue
}
}
type FetchOfflineModeActionForPO = {
type: '@@network-connectivity/FETCH_OFFLINE_MODE',
payload: {
prevAction: {
type: string, // Your previous action type
payload?: any, // Your previous payload
}
}
}
createNetworkMiddleware(config: MiddlewareConfig): ReduxMiddleware
type MiddlewareConfig = {
regexActionType?: RegExp = /FETCH.*REQUEST/,
actionTypes?: Array<string> = [],
queueReleaseThrottle?: number = 50,
shouldDequeueSelector: (state: RootReduxState) => boolean = () => true
}
import { createStore, applyMiddleware } from 'redux';
import { createNetworkMiddleware } from 'react-native-offline';
import createSagaMiddleware from 'redux-saga';
const sagaMiddleware = createSagaMiddleware();
const networkMiddleware = createNetworkMiddleware({
queueReleaseThrottle: 200,
});
const store = createStore(
const OfflineBanner = () => {
const [isOffline] = useNetworkInfo();
if (isOffline) {
return (
<View style={styles.container}>
<View style={styles.row}>
<Text>You are currently offline</Text>
</View>
</View>
const isConnectedSelector = state => state.network.isConnected;
const useNetworkInfo = () => {
const isConnected = useSelector(isConnectedSelector);
return [isConnected];
}
type NetworkState = {
isConnected: boolean,
actionQueue: Array<*>
}