implement use_async_memo with reactive context

This commit is contained in:
Jonathan Kelley committed 2024-02-01 13:21:53 -08:00
1 parent 7c2947a131
commit dd06705ff1
7 files changed
+68 -58

No files matched your search

+13 -1
View File
@@ -1,3 +1,5 @@
use std::time::Duration;
use dioxus::prelude::*;
fn main() {
@@ -23,7 +25,17 @@ fn app() -> Element {
fn Child(sig: Signal<i32>) -> Element {
let doubled = use_memo(move || sig() * 2);
let tripled = use_async_memo(move || async move {
tokio::time::sleep(Duration::from_millis(200)).await;
sig() * 3
});
let trippled = use_memo(move || match tripled.value() {
Some(v) => v.cloned(),
None => 1338,
});
rsx! {
"The count is: {sig}, doubled: {doubled}"
"The count is: {sig}, doubled: {doubled}, tripled: {trippled}"
}
}