Reputation: 563
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
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