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
{{ message }}
This repository was archived by the owner on Apr 28, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: docs/api-reference/browser_storage.md
+101-1Lines changed: 101 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,9 +142,74 @@ rx.button(
142
142
)
143
143
```
144
144
145
+
## rx.SessionStorage
146
+
147
+
Represents a state Var that is stored in sessionStorage in the browser. Similar to localStorage, but the data is cleared when the page session ends (when the browser/tab is closed). Currently only supports string values.
148
+
149
+
Parameters
150
+
151
+
-`name`: The name of the storage key on the client side.
152
+
-`sync`: Boolean indicates if the state should be kept in sync across tabs of the same browser.
153
+
154
+
```python
155
+
classSessionStorageState(rx.State):
156
+
# session storage with default settings
157
+
s1: str= rx.SessionStorage()
158
+
159
+
# session storage with custom settings
160
+
s2: str= rx.SessionStorage("s2 default")
161
+
s3: str= rx.SessionStorage(name="s3")
162
+
163
+
# session storage that automatically updates in other states across tabs
164
+
s4: str= rx.SessionStorage(sync=True)
165
+
```
166
+
167
+
### Session Persistence
168
+
169
+
SessionStorage data is cleared when the page session ends. A page session lasts as long as the browser is open and survives page refreshes and restores, but is cleared when the tab or browser is closed.
170
+
171
+
Unlike LocalStorage, SessionStorage is isolated to the tab/window in which it was created, so it's not shared with other tabs/windows of the same origin.
172
+
173
+
## rx.remove_session_storage
174
+
175
+
Remove a session storage item from the client's browser.
176
+
177
+
Parameters
178
+
179
+
-`key`: The key to remove from session storage.
180
+
181
+
```python
182
+
rx.button(
183
+
'Remove Session Storage',
184
+
on_click=rx.remove_session_storage('key'),
185
+
)
186
+
```
187
+
188
+
This event can also be returned from an event handler:
Clear all session storage items from the client's browser. This may affect other
200
+
apps running in the same domain or libraries within your app that use session
201
+
storage.
202
+
203
+
```python
204
+
rx.button(
205
+
'Clear all Session Storage',
206
+
on_click=rx.clear_session_storage(),
207
+
)
208
+
```
209
+
145
210
# Serialization Strategies
146
211
147
-
If a non-trivial data structure should be stored in a `Cookie`or `LocalStorage` var it needs to be serialized before and after storing it. It is recommended to use a dataclass for the data which provides simple serialization helpers and works recursively in complex object structures.
212
+
If a non-trivial data structure should be stored in a `Cookie`, `LocalStorage`, or `SessionStorage` var it needs to be serialized before and after storing it. It is recommended to use a dataclass for the data which provides simple serialization helpers and works recursively in complex object structures.
148
213
149
214
```python demo exec
150
215
import reflex as rx
@@ -234,3 +299,38 @@ def app_settings_example():
234
299
),
235
300
)
236
301
```
302
+
303
+
# Comparison of Storage Types
304
+
305
+
Here's a comparison of the different client-side storage options in Reflex:
0 commit comments