2023-06-07 15:09:43 +00:00
|
|
|
import NetInfo, { NetInfoState, NetInfoStateType } from '@react-native-community/netinfo';
|
|
|
|
|
2023-06-30 14:26:46 +00:00
|
|
|
import { setNetInfoState } from '../../actions/app';
|
2023-06-07 15:09:43 +00:00
|
|
|
|
|
|
|
export default () =>
|
|
|
|
(createStore: any) =>
|
|
|
|
(...args: any) => {
|
|
|
|
const store = createStore(...args);
|
|
|
|
let currentType: NetInfoStateType | undefined;
|
|
|
|
const handleInternetStateChange = (nextState: NetInfoState) => {
|
|
|
|
if (nextState.type !== currentType) {
|
2023-06-30 14:26:46 +00:00
|
|
|
store.dispatch(setNetInfoState(nextState.type));
|
2023-06-07 15:09:43 +00:00
|
|
|
currentType = nextState.type;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
NetInfo.addEventListener(handleInternetStateChange);
|
|
|
|
return store;
|
|
|
|
};
|