Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.

Commit 4076c03

Browse files
authored
Convert a few usages of rx.base to dataclasses (#1794)
* convert ones i can find * remove those references from docs as well * precommit * use reflex enterprise
1 parent 60bb9d6 commit 4076c03

6 files changed

Lines changed: 40 additions & 24 deletions

File tree

docs/enterprise/drag-and-drop.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,12 @@ def state_tracking_example():
216216
Create dynamic draggable lists using `rx.foreach`:
217217

218218
```python demo exec
219+
import dataclasses
219220
import reflex as rx
220221
import reflex_enterprise as rxe
221222

222-
class ListItem(rx.Base):
223+
@dataclasses.dataclass
224+
class ListItem:
223225
id: str
224226
text: str
225227
list_id: str

docs/getting_started/dashboard_tutorial.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ You can see what the finished app and code will look like here:
2727

2828

2929
```python exec
30+
import dataclasses
3031
from collections import Counter
3132

32-
class User(rx.Base):
33+
@dataclasses.dataclass
34+
class User:
3335
"""The user model."""
3436

3537
name: str
@@ -181,7 +183,8 @@ rx.vstack(
181183
import reflex as rx
182184
from collections import Counter
183185

184-
class User(rx.Base):
186+
@dataclasses.dataclass
187+
class User:
185188
"""The user model."""
186189

187190
name: str
@@ -616,14 +619,15 @@ So far our data has been defined in a list of lists, where the data is accessed
616619

617620
A better way to structure our data in Reflex is to use a class to represent a user. This way we can access the data using attributes i.e. `user.name`, `user.email`.
618621

619-
In Reflex when we create these classes to showcase our data, the class must inherit from `rx.Base`.
620-
621-
`rx.Base` is also necessary if we want to have a state var that is an iterable with different types. For example if we wanted to have `age` as an `int` we would have to use `rx.base` as we could not do this with a state var defined as `list[list[str]]`.
622+
In Reflex when we create these classes to showcase our data, we can use dataclasses.
622623

623624
The `show_user` render function is also updated to access the data by named attributes, instead of indexing.
624625

625626
```python exec
626-
class User(rx.Base):
627+
import dataclasses
628+
629+
@dataclasses.dataclass
630+
class User:
627631
"""The user model."""
628632

629633
name: str
@@ -670,7 +674,8 @@ rx.table.root(
670674

671675

672676
```python
673-
class User(rx.Base):
677+
@dataclasses.dataclass
678+
class User:
674679
"""The user model."""
675680

676681
name: str
@@ -1119,7 +1124,8 @@ rx.vstack(
11191124
```
11201125

11211126
```python
1122-
class User(rx.Base):
1127+
@dataclasses.dataclass
1128+
class User:
11231129
"""The user model."""
11241130

11251131
name: str
@@ -1663,7 +1669,8 @@ rx.vstack(
16631669
import reflex as rx
16641670
from collections import Counter
16651671

1666-
class User(rx.Base):
1672+
@dataclasses.dataclass
1673+
class User:
16671674
"""The user model."""
16681675

16691676
name: str

pcweb/components/docpage/sidebar/state.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass, field
6+
57
import reflex as rx
6-
from reflex.base import Base
78

89

9-
class SideBarBase(Base):
10+
@dataclass(kw_only=True)
11+
class SideBarBase:
1012
"""Base class for the Side bar."""
1113

1214
# The name to display in the sidebar.
@@ -18,7 +20,7 @@ class SideBarBase(Base):
1820
link: str = ""
1921

2022
# The children items.
21-
children: list[SideBarItem] = []
23+
children: list[SideBarItem] = field(default_factory=list)
2224

2325
# Whether the item is a category. Occurs if a single item is at the top level of the sidebar for aesthetics.
2426
outer = False

pcweb/pages/docs/apiref.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
modules = [
1010
rx.App,
11-
rx.Base,
1211
rx.Component,
1312
rx.ComponentState,
1413
(rx.Config, rx.config.BaseConfig),

pcweb/pages/docs/component.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ class PropDocsState(rx.State):
7878

7979
def render_select(prop: PropDocumentation, component: type[Component], prop_dict: dict):
8080
if (
81-
not rx.utils.types._issubclass(
82-
component, (RadixThemesComponent, RadixPrimitiveComponent)
83-
)
81+
not safe_issubclass(component, (RadixThemesComponent, RadixPrimitiveComponent))
8482
or component.__name__ in EXCLUDED_COMPONENTS
8583
):
8684
return rx.fragment()
8785
try:
88-
type_ = rx.utils.types.get_args(prop.type)[0]
86+
type_ = get_args(prop.type)[0]
8987
except Exception:
9088
return rx.fragment()
9189

@@ -249,6 +247,13 @@ def color_scheme_hovercard(literal_values: list[str]) -> rx.Component:
249247
)
250248

251249

250+
def safe_issubclass(cls, class_or_tuple):
251+
try:
252+
return issubclass(cls, class_or_tuple)
253+
except TypeError:
254+
return False
255+
256+
252257
def prop_docs(
253258
prop: PropDocumentation,
254259
prop_dict: dict,
@@ -258,9 +263,10 @@ def prop_docs(
258263
"""Generate the docs for a prop."""
259264
# Get the type of the prop.
260265
type_ = prop.type
261-
if rx.utils.types._issubclass(prop.type, rx.Var):
266+
origin = get_origin(type_)
267+
if safe_issubclass(origin, rx.Var):
262268
# For vars, get the type of the var.
263-
type_ = rx.utils.types.get_args(type_)[0]
269+
type_ = get_args(type_)[0]
264270

265271
origin = get_origin(type_)
266272
args = get_args(type_)
@@ -448,7 +454,7 @@ def generate_props(
448454
prop_dict = {}
449455

450456
is_interactive = True
451-
if not rx.utils.types._issubclass(
457+
if not issubclass(
452458
component, (RadixThemesComponent, RadixPrimitiveComponent)
453459
) or component.__name__ in [
454460
"Theme",

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)