Flora
Flora

Reputation: 563

react redux: Call a function if a socket event was called

I use React with Redux. I wait for a socket event 'connect' inside a component no. 1. When the socket is connected then I want to call some function inside a component no. 2. How to do this?

Upvotes: 0

Views: 203

Answers (1)

Ben
Ben

Reputation: 254

If you are using socket.io you should be able to do this:

socket.on('connect', () => {
  yourFunction()
});

You could place that inside the componentWillMount() lifecycle hook of your component and then just call the function of your component with the regular this.yourFunction().

You can read more about the available client events here: Socket.IO Client API

Upvotes: 1

Related Questions