DEV Community

Discussion on: A Socket.io tutorial that ISN'T a chat app (with React.js)

Collapse
 
ajaypatel profile image
FoodBite

Hey i have a question, i am making chat app ,so where should i put my socket.on() method to continuously update the state without calling it explicitly.
I am noob in react, please help, thanks in advance

Collapse
 
captainpandaz profile image
Talha Muhammad

Hey! Sorry about the late response.

I'm going to assume that you're asking about where to put socket.on() on the client app (which im also assuming is in react).

I'm also going to assume you aren't using hooks since this tutorial did not have hooks (hooks are awesome btw)

If both of these are valid, you can add the "listener" to a components componentDidMount lifecycle method, just like I did above.

You can read more about the method here: reactjs.org/docs/react-component.h...