Implement effects using reactivecontext

This commit is contained in:
Jonathan Kelley committed 2024-02-01 13:21:52 -08:00
1 parent 968f24a7b3
commit 7c2947a131
21 files changed
+287 -320

No files matched your search

+15
View File
@@ -7,8 +7,23 @@ fn main() {
fn app() -> Element {
let mut count = use_signal(|| 0);
use_effect(move || {
println!("The count is now: {}", count);
});
rsx! {
h1 { "High-Five counter: {count}" }
Child { sig: count }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
}
#[component]
fn Child(sig: Signal<i32>) -> Element {
let doubled = use_memo(move || sig() * 2);
rsx! {
"The count is: {sig}, doubled: {doubled}"
}
}