implement use_async_memo with reactive context
This commit is contained in:
7 files changed
+68
-58
No files matched your search
+13
-1
@@ -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}"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user