You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[derive(Clone, strum::EnumIter,Routable,Debug,PartialEq, serde::Serialize, serde::Deserialize)]enumRoute{#[route("/")]Home{},#[route("/counter")]Counter{},#[route("/blog/:id")]Blog{id:i32},}implRoute{fnicon(&self) -> String{matchself{Route::Home{} => "home".into(),Route::Counter{} => "add_circle".into(),Route::Blog{ .. } => "blog".into(),}}fntitle(&self) -> String{matchself{Route::Home{} => "Home".into(),Route::Counter{} => "Counter".into(),Route::Blog{ .. } => "Blog".into(),}}}#[component]fnRailDrawerNav() -> Element{let nav_buttons = Route::iter().map(|route| {let icon = route.icon();let title = route.title();rsx!{Link{ to: route,
i {"{icon}"}
div {"{title}"}}}});rsx!{
nav { class: "left drawer l",
header {
nav {
img {
src: "https://www.beercss.com/favicon.png",
class: "circle"}
h6 {"Cheers"}}}for button in nav_buttons {{ button }}
div { class: "divider"}
a {
i {"search"}
div {"Search"}}
a {
i {"share"}
div {"Share"}}
a {
i {"more_vert"}
div {"More"}}}}}#[component]fnBlog(id:i32) -> Element{rsx!{RailDrawerNav{}// ...}}
But the following does not work (why does the analyzer show an irrelevant missing trailing comma error?):
#[component]fnRailDrawerNav() -> 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,
i { route.icon()}// missing trailing comma rust-analyzer[macro-error]
div { route.title()}}}// ...}// ...}}
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 and title as attribute keys, not values:
let nav_buttons = Route::iter().map(|route| {let icon = route.icon();let title = route.title();rsx!{Link{ to: route,
i { icon }
div { title }}}});
Steps To Reproduce
Try the above code snippets.
Expected behavior
It is likely expected. However, it would be helpful to have:
Better tutorial docs on dealing with things like properties / methods of things. If I had a say, this would be a high priority as it should be an easy fix for the maintainers knowing how it should work. Just a quick example section would be great, because it's probably a very common stumbling block for newcomers.
A better analyzer error (not trailing comma) -- I saw another issue that suggests this might be in the works but don't know if related. Probably much harder fix, knowing Rust macro analyzer limitations.
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}" }
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.
The text was updated successfully, but these errors were encountered:
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:
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 DioxusLabs/docsite#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.
The text was updated successfully, but these errors were encountered: