mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-14 00:17:17 +00:00
20d146d9bd
* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Simplify the launch builder * don't re-export launch in the prelude * refactor fullstack launch * Fix fullstack launch builder * Update static generation with the new builder api * fix some formatting/overly broad launch replacements * fix custom menu example * fix fullstack/static generation examples * Fix static generation launch * A few small formatting fixes * Fix a few doc tests * implement LaunchConfig for serve configs * fix fullstack launch with separate web and server launch methods * fix check with all features * dont expose inner core module * clippy and check * fix readme --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
38 lines
976 B
Rust
38 lines
976 B
Rust
//! A simple example that shows how to use the use_future hook to run a background task.
|
|
//!
|
|
//! use_future won't return a value, analogous to use_effect.
|
|
//! If you want to return a value from a future, use use_resource instead.
|
|
|
|
use async_std::task::sleep;
|
|
use dioxus::prelude::*;
|
|
|
|
fn main() {
|
|
dioxus::launch(app);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
let mut count = use_signal(|| 0);
|
|
|
|
// use_future will run the future
|
|
use_future(move || async move {
|
|
loop {
|
|
sleep(std::time::Duration::from_millis(200)).await;
|
|
count += 1;
|
|
}
|
|
});
|
|
|
|
// We can also spawn futures from effects, handlers, or other futures
|
|
use_effect(move || {
|
|
spawn(async move {
|
|
sleep(std::time::Duration::from_secs(5)).await;
|
|
count.set(100);
|
|
});
|
|
});
|
|
|
|
rsx! {
|
|
div {
|
|
h1 { "Current count: {count}" }
|
|
button { onclick: move |_| count.set(0), "Reset the count" }
|
|
}
|
|
}
|
|
}
|