'How to listen to socket.io events across all components/screens or globally in react-native?
I am using socket.io(server) and socket.io-client(client) in react-native app and I am listening to its events in useEffect hook, all events are receiving correctly when I am on that specific component.
So how can can I receive these events on the other screens too??
Single instance for all events which will be used globally
e.g:
const app = () => {
useEffect(() => {
socket.on('event', (data) => {
console.log(data)
}
},[])
...................
rest of the code
...................
}
Now I want to listen to this event on all the screens (like DeviceEventEmitter addListner works)?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
