'Socket.io in React Native using Context
I'm trying to use socket.io in my app but for some reason the socket continuously reconnects to the socket server. I've wrapped the socket.io instance in context (example below):
import io from 'socket.io-client';
export const socket = io('http://192.168.10.123:3000', {
autoConnect: false,
transports: ['websocket'],
});
const SocketContext = createContext(socket);
export default SocketContext;
I'm using it in my app like this:
<SocketContext.Provider value={socket}>
<NavigationContainer>
<App />
</NavigationContainer>
</SocketContext.Provider>
I've tried many different solutions, one of them was to downgrade to 2.1.1 but this is more than 2 major versions below latest so I don't really want to do so.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
