Skip to content

Commit f63e9e0

Browse files
committed
document conditional attributes
1 parent fe956ac commit f63e9e0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docs-src/0.5/en/reference/context.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We start with a `Meme` component, responsible for rendering a meme with a given
1616
{{#include src/doc_examples/meme_editor.rs:meme_component}}
1717
```
1818

19-
> Note that the `Meme` component is unaware where the caption is coming from – it could be stored in `use_signal`, `use_signal`, or a constant. This ensures that it is very reusable – the same component can be used for a meme gallery without any changes!
19+
> Note that the `Meme` component is unaware where the caption is coming from – it could be stored in `use_signal`, or a constant. This ensures that it is very reusable – the same component can be used for a meme gallery without any changes!
2020
2121
We also create a caption editor, completely decoupled from the meme. The caption editor must not store the caption itself – otherwise, how will we provide it to the `Meme` component? Instead, it should accept the current caption as a prop, as well as an event handler to delegate input events to:
2222

docs-src/0.5/en/reference/rsx.md

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ DemoFrame {
4242
4343
> Note: Styles can be used directly outside of the `style:` attribute. In the above example, `color: "red"` is turned into `style="color: red"`.
4444
45+
#### Conditional Attributes
46+
47+
You can also conditionally include attributes by using an if statement without an else branch. This is useful for adding an attribute only if a certain condition is met:
48+
49+
```rust, no_run
50+
{{#include src/doc_examples/rsx_overview.rs:conditional_attributes}}
51+
```
52+
53+
```inject-dioxus
54+
DemoFrame {
55+
rsx_overview::ConditionalAttributes {}
56+
}
57+
```
58+
4559
#### Custom Attributes
4660

4761
Dioxus has a pre-configured set of attributes that you can use. RSX is validated at compile time to make sure you didn't specify an invalid attribute. If you want to override this behavior with a custom attribute name, specify the attribute in quotes:

src/doc_examples/rsx_overview.rs

+10
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ pub fn CustomAttributes() -> Element {
8686
// ANCHOR_END: custom_attributes
8787
}
8888

89+
pub fn ConditionalAttributes() -> Element {
90+
// ANCHOR: conditional_attributes
91+
let large_font = true;
92+
rsx!( div {
93+
class: if large_font { "text-xl" },
94+
"Hello, World!"
95+
} )
96+
// ANCHOR_END: conditional_attributes
97+
}
98+
8999
pub fn Formatting() -> Element {
90100
// ANCHOR: formatting
91101
let coordinates = (42, 0);

0 commit comments

Comments
 (0)