I'm trying to listen the network status using eventChannel from redux saga like this:
import {put, take} from 'redux-saga/effects';
import {eventChannel} from 'redux-saga';
import NetInfo from '@react-native-community/netinfo';
export function* startWatchingNetworkConnectivity() {
const channel = eventChannel((emitter) => {
NetInfo.addEventListener('connectionChange', emitter);
return () => NetInfo.removeEventListener('connectionChange', emitter);
});
try {
while (true) {
const isConnected = yield take(channel);
if (isConnected) {
yield put({type: 'ONLINE'});
} else {
yield put({type: 'OFFLINE'});
}
}
} finally {
channel.close();
}
}
But I'm getting the following error TypeError: handler is not a function in const isConnected = yield take(channel);
I've got this idea from here
I've just got the problem
You need to call the event listener like this: