Open tgrushka opened 2 weeks ago
Wait 2 milliseconds!
I think I found it (wrap method calls in extra { ... }
:
#[component]
fn RailDrawerNav() -> Element {
rsx! {
nav { class: "left drawer l",
header {
nav {
img {
src: "https://www.beercss.com/favicon.png",
class: "circle"
}
h6 { "Cheers" }
}
}
for route in Route::iter() {
Link { to: route.clone(),
i { { route.icon() } }
div { { route.title() } }
}
}
// ...
Would be happy to contribute a docs PR.
Dioxus rsx is similar to rust structs, if you have a plain ident with the name of an attribute, then it set the attribute (like Foo { bar }
sets the fieled bar to the value bar). This is documented here:
1) In the rsx reference: https://dioxuslabs.com/learn/0.5/reference/rsx#expressions
2) In the (new 0.6 only) rsx inline docs: https://docs.rs/dioxus/0.6.0-alpha.3/dioxus/prelude/macro.rsx.html#raw-expressions
3) In the (new 0.6 only) examples alongside element: https://docs.rs/dioxus-html/0.6.0-alpha.3/dioxus_html/elements/div/index.html#usage-in-rsx
I think we can improve the macro error message for that parsing case. It would be helpful to hear what documentation you have read before running into this issue so that we know where cross links need to be added. There are some plans to expand the guide in https://github.com/DioxusLabs/docsite/pull/277
(Is it a) Problem (/ Rust limitation?)
The following works (awesome!):
But the following does not work (why does the analyzer show an irrelevant missing trailing comma error?):
Was hoping to do that, but then it became only slightly clearer when I found this compiles, but yields improper output because it's interpreting
icon
andtitle
as attribute keys, not values:Steps To Reproduce
Try the above code snippets.
Expected behavior
It is likely expected. However, it would be helpful to have:
Screenshots
Unwanted render trying the last method above (unquoted var name as node content, i.e.
div { title }
):Correct render with quoted var names, i.e.
div { "{title}" }
Environment:
stable
-->Questionnaire
I would like to help fix this by helping with documentation but I'm brand new to this framework so I'm not sure of the recommended way to deal with this issue. If I knew, would be happy to write up a PR for the docs.