dioxus/tests/borrowedstate.rs

47 lines
844 B
Rust
Raw Normal View History

2021-10-22 01:16:39 -04:00
#![allow(non_snake_case)]
use dioxus::prelude::*;
2021-09-21 13:13:15 -04:00
2021-10-22 01:16:39 -04:00
#[test]
fn test_borrowed_state() {
let _ = VirtualDom::new(Parent);
}
2021-12-29 21:28:28 -05:00
fn Parent(cx: Scope) -> Element {
let value = cx.use_hook(|_| String::new());
2021-09-21 13:13:15 -04:00
cx.render(rsx! {
2021-09-21 13:13:15 -04:00
div {
Child { name: value }
Child { name: value }
Child { name: value }
Child { name: value }
}
})
2021-10-22 01:16:39 -04:00
}
2021-09-21 13:13:15 -04:00
#[derive(Props)]
struct ChildProps<'a> {
2021-10-22 01:16:39 -04:00
name: &'a str,
2021-09-21 13:13:15 -04:00
}
2021-12-14 21:46:19 -05:00
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
cx.render(rsx! {
2021-09-21 13:13:15 -04:00
div {
h1 { "it's nested" }
2021-12-14 21:46:19 -05:00
Child2 { name: cx.props.name }
2021-09-21 13:13:15 -04:00
}
})
2021-09-21 13:13:15 -04:00
}
#[derive(Props)]
struct Grandchild<'a> {
2021-10-22 01:16:39 -04:00
name: &'a str,
2021-09-21 13:13:15 -04:00
}
2021-12-14 21:46:19 -05:00
fn Child2<'a>(cx: Scope<'a, Grandchild<'a>>) -> Element {
cx.render(rsx! {
2021-12-14 21:46:19 -05:00
div { "Hello {cx.props.name}!" }
})
2021-09-21 13:13:15 -04:00
}