|
@@ -14,6 +14,7 @@ fn app(cx: Scope) -> Element {
|
|
|
cx.render(rsx! {
|
|
|
div { "hello {name}!" }
|
|
|
Child {}
|
|
|
+ ChildWithRef{}
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -27,3 +28,27 @@ fn Child(cx: Scope) -> Element {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+static NAMES: AtomRef<Vec<String>> = |_| vec!["world".to_string()];
|
|
|
+
|
|
|
+fn ChildWithRef(cx: Scope) -> Element {
|
|
|
+ let names = use_atom_ref(&cx, NAMES);
|
|
|
+
|
|
|
+ cx.render(rsx! {
|
|
|
+ div {
|
|
|
+ ul {
|
|
|
+ names.read().iter().map(|f| rsx!{
|
|
|
+ li { "hello: {f}" }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ button {
|
|
|
+ onclick: move |_| {
|
|
|
+ let names = names.clone();
|
|
|
+ cx.spawn(async move {
|
|
|
+ names.write().push("asd".to_string());
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|