add an optional cleanup closure to the use effect hook

This commit is contained in:
Evan Almloff committed 2023-11-19 09:58:00 -06:00
1 parent 098689083d
commit 83f7ef9a44
2 files changed
+76 -9

No files matched your search

+6
View File
@@ -11,6 +11,12 @@ fn main() {
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
use_effect(cx, (), move |()| async {});
use_effect(cx, (count.get(),), move |(count,)| async move {
move || println!("Count unmounted from {}", count)
});
cx.render(rsx! {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }