fix: connect websocket when the component mounts (#5456)

This commit is contained in:
Elias Nahum
2021-06-14 15:48:39 -04:00
committed by GitHub
parent 4e2972782f
commit 0e81e0e2a8

View File

@@ -111,10 +111,7 @@ const NetworkIndicator = ({
};
const handleConnectionChange = ({hasInternet}: ConnectionChangedEvent) => {
if (firstRun.current) {
firstRun.current = false;
handleWebSocket(true);
} else {
if (!firstRun.current) {
if (!hasInternet) {
setConnected(false);
}
@@ -150,6 +147,11 @@ const NetworkIndicator = ({
}
};
useEffect(() => {
handleWebSocket(true);
firstRun.current = false;
}, []);
useEffect(() => {
const networkListener = networkConnectionListener(handleConnectionChange);
return () => networkListener.removeEventListener();
@@ -168,7 +170,6 @@ const NetworkIndicator = ({
useEffect(() => {
const handleAppStateChange = stateChange(async (appState: AppStateStatus) => {
const active = appState === 'active';
handleWebSocket(active);
if (active) {