Skip to content

Commit bfd94ff

Browse files
LendemorAlek99
andauthored
remove state inheritance docs (#1441)
* remove state inheritance docs * fix imports * restore some stuff and clean up * remove line * add warning for component state in foreach --------- Co-authored-by: Alek Petuskey <[email protected]>
1 parent 8d4841d commit bfd94ff

File tree

7 files changed

+14
-42
lines changed

7 files changed

+14
-42
lines changed

blog/2024-04-16-custom-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ meta: [
1010
---
1111

1212
```python exec
13-
from pcweb.pages.docs import wrapping_react, custom_components, styling, events, getting_started, substates
13+
from pcweb.pages.docs import wrapping_react, custom_components, styling, events, getting_started, state_structure
1414
from pcweb.pages.docs.custom_components import custom_components as cc
1515
```
1616

@@ -118,7 +118,7 @@ def counter_sum():
118118
)
119119
```
120120

121-
See the [Component State]({substates.component_state.path}) page for more details on how to use this class.
121+
See the [Component State]({state_structure.component_state.path}) page for more details on how to use this class.
122122

123123
## Testing and Publishing
124124

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ instance of a component, rather than existing globally in the app. A Component S
1313
[Event Handlers]({events.events_overview.path}),
1414
and is useful for creating reusable components which operate independently of each other.
1515

16+
```md alert warning
17+
# ComponentState cannot be used inside `rx.foreach()` as it will only create one state instance for all elements in the loop. Each iteration of the foreach will share the same state, which may lead to unexpected behavior.
18+
```
19+
1620
## Using ComponentState
1721

1822
```python demo exec
Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,38 +90,6 @@ def index():
9090
)
9191
```
9292

93-
## State Inheritance
94-
95-
A substate can also inherit from another substate other than `rx.State`, allowing you to create a hierarchy of states.
96-
97-
For example, you can create a base state that defines variables and event handlers that are common to all pages in your app, such as the current logged in user.
98-
99-
```python
100-
class BaseState(rx.State):
101-
"""Define your base state here."""
102-
103-
current_user: str = ""
104-
105-
def logout(self):
106-
self.current_user = ""
107-
108-
109-
class LoginState(BaseState):
110-
"""Define your login state here."""
111-
112-
username: str = ""
113-
password: str = ""
114-
115-
def login(self, username, password):
116-
# authenticate
117-
authenticate(...)
118-
119-
# Set the var on the parent state.
120-
self.current_user = username
121-
```
122-
123-
You can access the parent state properties from a child substate automatically.
124-
12593
## Accessing Arbitrary States
12694

12795
An event handler in a particular state can access and modify vars in another state instance by calling
@@ -261,4 +229,4 @@ data is loaded for processing events for a particular page or component.
261229
Avoid defining computed vars inside a state that contains a large amount of data, as
262230
states with computed vars are always loaded to ensure the values are recalculated.
263231
When using computed vars, it better to define them in a state that directly inherits from `rx.State` and
264-
does not have other states inheriting from it, to avoid loading unnecessary data.
232+
does not have other states inheriting from it, to avoid loading unnecessary data.

pcweb/components/docpage/sidebar/sidebar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def sidebar_icon(name):
137137
"Wrapping React": "atom",
138138
"Vars": "variable",
139139
"Events": "arrow-left-right",
140-
"Substates": "boxes",
140+
"State Structure": "boxes",
141141
"API Routes": "route",
142142
"Client Storage": "package-open",
143143
"Database": "database",

pcweb/components/docpage/sidebar/sidebar_items/learn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ def get_sidebar_items_backend():
117117
api_routes,
118118
authentication,
119119
client_storage,
120+
state_structure,
120121
database,
121122
events,
122123
state,
123-
substates,
124124
utility_methods,
125125
vars,
126126
)
@@ -154,10 +154,10 @@ def get_sidebar_items_backend():
154154
],
155155
),
156156
create_item(
157-
"Substates",
157+
"State Structure",
158158
children=[
159-
substates.overview,
160-
substates.component_state,
159+
state_structure.overview,
160+
state_structure.component_state,
161161
],
162162
),
163163
create_item(

pcweb/pages/docs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def exec_blocks(doc, href):
122122
"docs/custom-components/overview.md": "Custom Components Overview",
123123
"docs/api-routes/overview.md": "API Routes Overview",
124124
"docs/client_storage/overview.md": "Client Storage Overview",
125+
"docs/state_structure/overview.md": "State Structure Overview",
125126
"docs/state/overview.md": "State Overview",
126127
"docs/styling/overview.md": "Styling Overview",
127-
"docs/substates/overview.md": "Substates Overview",
128128
"docs/ui/overview.md": "UI Overview",
129129
"docs/wrapping-react/overview.md": "Wrapping React Overview",
130130
"docs/library/html/html.md": "HTML Elements",

pcweb/pcweb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
("/docs/wrapping-react", "/docs/wrapping-react/overview"),
105105
("/docs/vars", "/docs/vars/base-vars"),
106106
("/docs/events", "/docs/events/events-overview"),
107-
("/docs/substates", "/docs/substates/overview"),
107+
("/docs/state-structure", "/docs/state-structure/overview"),
108108
("/docs/api-routes", "/docs/api-routes/overview"),
109109
("/docs/client-storage", "/docs/client-storage/overview"),
110110
("/docs/authentication", "/docs/authentication/authentication-overview"),

0 commit comments

Comments
 (0)