Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Is it optimal to manage room subscription hooks with this.forceUpdate()? #9

Open
mikemklee opened this issue Jun 13, 2018 · 2 comments

Comments

@mikemklee
Copy link

In the tutorial, the room subscription hooks such as onUserCameOnline or onUserJoined are set up so that they invoke this.forceUpdate(). However, according to the React Docs, using forceUpdate() is discouraged. Are there other ways in which I can manage room subscription hooks other than using forceUpdate()?

@bookercodes
Copy link
Contributor

Yeah, absolutely!

In the onUserCameOnline and onUserJoined hooks, you can update your state. For example,

onUserCameOnline: user => {
  this.setState({
    users: [...this.state.users, user]
  }}
}

Thing is, Chatkit mutates currentRoom.users for us so you don't actually have to track users yourself.

You could do:

onUserCameOnline: user => {
  this.setState({
    users: this.currentRoom.users
  }}
}

And that wold be okay too!

In my opinion, there is no practical downside to using forceUpdate here but again, this is a demo. In a more complicated app, I am not sure what the implications would be.

@mikemklee
Copy link
Author

Thanks! I actually have two more questions. I am not sure if this is the right place to ask questions, but here they are:

  1. After following the tutorial, I am making my own version of the app and I plan to deploy it to heroku. I want to deploy both the express server and the react client simultaneously. Do you know of any resources that may guide me through this process?

  2. Instead of exposing the key for the Chatkit API on public repo, I plan to conceal any sensitive info in env variables. I am hiding the Chakit secret key for sure, but do I also need to hide the instance locator key?

Thanks for reading! You guys are awesome :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants