#attribute
5 messages · Page 1 of 1 (latest)
You can pass in Option<&str> to style:
#![allow(non_snake_case)]
use dioxus::prelude::*;
fn main() {
dioxus_web::launch(app);
}
fn app(cx: Scope) -> Element {
let style: Option<&str> = None;
cx.render(rsx! {
div {
style: style,
}
})
}
will render <div></div>
and
#![allow(non_snake_case)]
use dioxus::prelude::*;
fn main() {
dioxus_web::launch(app);
}
fn app(cx: Scope) -> Element {
let style: Option<&str> = Some("background-color: red;");
cx.render(rsx! {
div {
style: style,
}
})
}
will render <div style="background-color: red;"></div>
I tried that, but it complained that Option<&str> does not implement Display
style: "{style}" will not work, but style: style should work
The "{}" makes the attribute formatted, if you leave them out it is a raw attribute of one of these values: https://docs.rs/dioxus-core/0.3.2/dioxus_core/enum.AttributeValue.html
Any of the built-in values that the Dioxus VirtualDom supports as dynamic attributes on elements