Use Socket.io I would like to use state to handle the events my socket is listening too. The issue is that once the socket event name is set I can't change it. What I am hoping to do is have socket.io listen to events with eventName start. Then if a button is pressed socket.io will listen to events with different new eventName
state = {
channel:'start'
};
componentDidMount() {
// .. lots of other stuff
apiListener()
}
apiListener = () => {
mySocket.on(this.state.channel, data => {
console.log(data)
})
}
render(){
return(
<View>
<Button onPress={()=> setState({channel: 'great'})} />
<Button onPress={()=> setState({channel: 'better'})} />
</View>
)
}