2022-01-02 23:35:38 +00:00
|
|
|
//! This example just flexes the ability to use arbitrary expressions within RSX.
|
|
|
|
//! It also proves that lifetimes work properly, especially when used with use_ref
|
|
|
|
|
2021-12-30 08:14:47 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut vdom = VirtualDom::new(example);
|
2022-12-07 00:37:28 +00:00
|
|
|
_ = vdom.rebuild();
|
2021-12-30 08:14:47 +00:00
|
|
|
|
2022-12-07 01:50:25 +00:00
|
|
|
let mut renderer = dioxus_ssr::Renderer::new();
|
|
|
|
renderer.pretty = true;
|
|
|
|
renderer.render(&vdom);
|
2021-12-30 08:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn example(cx: Scope) -> Element {
|
2022-03-01 07:50:03 +00:00
|
|
|
let items = use_state(&cx, || {
|
2021-12-30 08:14:47 +00:00
|
|
|
vec![Thing {
|
|
|
|
a: "asd".to_string(),
|
|
|
|
b: 10,
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
let things = use_ref(&cx, || {
|
|
|
|
vec![Thing {
|
|
|
|
a: "asd".to_string(),
|
|
|
|
b: 10,
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
let things_list = things.read();
|
|
|
|
|
|
|
|
let mything = use_ref(&cx, || Some(String::from("asd")));
|
|
|
|
let mything_read = mything.read();
|
|
|
|
|
|
|
|
cx.render(rsx!(
|
|
|
|
div {
|
2022-09-13 21:57:23 +00:00
|
|
|
div { id: "asd",
|
2021-12-30 08:14:47 +00:00
|
|
|
"your neighborhood spiderman"
|
|
|
|
|
|
|
|
items.iter().cycle().take(5).map(|f| rsx!{
|
2022-09-13 21:57:23 +00:00
|
|
|
div { "{f.a}" }
|
2021-12-30 08:14:47 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
things_list.iter().map(|f| rsx!{
|
2022-09-13 21:57:23 +00:00
|
|
|
div { "{f.a}" "{f.b}" }
|
2021-12-30 08:14:47 +00:00
|
|
|
})
|
|
|
|
|
2022-09-13 21:57:23 +00:00
|
|
|
mything_read.as_ref().map(|f| rsx! {
|
|
|
|
div { "{f}" }
|
2021-12-30 08:14:47 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Thing {
|
|
|
|
a: String,
|
|
|
|
b: u32,
|
|
|
|
}
|