Share state between users while tracking individual user values in real-time collaborative applications
useStateTogetherWithPerUserValues
hook allows users to share state while also being able to read the individual state values of all their peers. Each user maintains their own state value, but can see everyone else’s values in real-time.
If the user is not connected to any session, the hook behaves like a normal useState
, and the peer state object will be empty.
true
, the user’s state will be persisted in the session even after disconnection.true
, the local value will not be included in the allValues
object.true
, the user will force its local value into the session.true
, the user’s state will be reset to initialValue
when the user connects to the session.true
, the user’s state will be reset to initialValue
after the user disconnects from the session. This only affects the user’s local state after disconnection.throttleDelay
based on your use caseuseStateTogether
- For shared state without per-user trackinguseConnectedUsers
- Get information about connected usersuseMyId
- Get the current user’s IDuseNicknames
- Manage user nicknamesinitialValue
parameter: