r/reactjs • • May 03 '18

Beginner's Thread / Easy Question (May 2018)

Pretty happy to see these threads getting a lot of comments - we had over 200 comments in last month's thread! If you didn't get a response there, please ask again here!

Soo... Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple.

The Reactiflux chat channels on Discord are another great place to ask for help as well.

25 Upvotes

267 comments sorted by

View all comments

Show parent comment

1

u/[deleted] May 24 '18

Hey anyway, just curious. If your react handles a real-time events like chatting, or live score, how do you separate concerns between the connection, updates from server, and the component itself? Have you tried it?

1

u/VariadicIntegrity May 24 '18

There's a few ways. The first that comes to mind for me would be to just make a container component that manages the websocket connection in its lifecycle methods and records the data you care about in state. It can then pass that data into a dumber component in its render method. That's worked well for me before.

Depending on how big the app is, and how many components need the data, you could move that logic into a context provider or a state management library if needed.