Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
how to change eventName with socket.io

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>
  )
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!