You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/state_structure/shared_state.md
+10-2Lines changed: 10 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,7 +138,9 @@ An `rx.SharedState` subclass has two attributes for determining link status and
138
138
139
139
Provides the token that the state is currently linked to, or empty string if not linked.
140
140
141
-
This attribute is only set on the linked state instance returned by `_link_to`. It will be an empty string on any unlinked shared state instances. However, if another state links to a client's private token, then the `_linked_to` attribute will be set to the client's token rather than empty string. This is yet another reason to avoid linking to client tokens directly.
141
+
This attribute is only set on the linked state instance returned by `_link_to`. It will be an empty string on any unlinked shared state instances. However, if another state links to a client's private token, then the `_linked_to` attribute will be set to the client's token rather than an empty string.
142
+
143
+
When `_linked_to` equals `self.router.session.client_token`, it is assumed that the current client is unlinked, but another client has linked to this client's private state. Although this is possible, it is generally discouraged to link shared states to private client tokens.
142
144
143
145
**`_linked_from: set[str]`**
144
146
@@ -159,6 +161,8 @@ Linked states are always loaded into the tree for each event on each linked clie
159
161
A shared state should primarily use backend-only vars (prefixed with an underscore) to store shared data. Often, not all users of the shared state need visibility into all of the data in the shared state. Use computed vars to provide sanitized access to shared data as needed.
160
162
161
163
```python
164
+
from typing import Literal
165
+
162
166
classSharedGameState(rx.SharedState):
163
167
# Sensitive user metadata stored in backend-only variable.
164
168
_players: dict[str, Literal["X", "O"]] = {}
@@ -197,11 +201,15 @@ It is often convenient to define dynamic routes that include the linked token as
197
201
```python
198
202
classSharedRoom(rx.SharedState):
199
203
asyncdefon_load(self):
204
+
# `self.room_id` is the automatically defined dynamic route var.
0 commit comments