Skip to content

Commit 8132759

Browse files
Add missing code example for optional rx.cond second argument (#1492)
- Added interactive example demonstrating rx.cond with only two arguments - Shows behavior when condition is false and no false component is provided - Addresses user feedback about missing code examples and behavior description - Follows existing documentation patterns with state management and visual feedback Co-Authored-By: unknown <> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 7b51031 commit 8132759

File tree

1 file changed

+17
-0
lines changed
  • docs/library/dynamic-rendering

1 file changed

+17
-0
lines changed

docs/library/dynamic-rendering/cond.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ def cond_example():
2828
The second component is optional and can be omitted.
2929
If it is omitted, nothing is rendered if the condition is `False`.
3030

31+
```python demo exec
32+
class CondOptionalState(rx.State):
33+
show_optional: bool = True
34+
35+
@rx.event
36+
def toggle_optional(self):
37+
self.show_optional = not (self.show_optional)
38+
39+
40+
def cond_optional_example():
41+
return rx.vstack(
42+
rx.button("Toggle", on_click=CondOptionalState.toggle_optional),
43+
rx.cond(CondOptionalState.show_optional, rx.text("This text appears when condition is True", color="green")),
44+
rx.text("This text is always visible", color="gray"),
45+
)
46+
```
47+
3148
```md video https://youtube.com/embed/ITOZkzjtjUA?start=6040&end=6463
3249
# Video: Conditional Rendering
3350
```

0 commit comments

Comments
 (0)