mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-25 13:40:19 +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>
64 lines
1.4 KiB
Rust
64 lines
1.4 KiB
Rust
//! Example: Updating components with use_resource
|
|
//! -----------------
|
|
//!
|
|
//! This example shows how to use ReadOnlySignal to make props reactive
|
|
//! when linking to it from the same component, when using use_resource
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
#[derive(Clone, Routable, Debug, PartialEq)]
|
|
enum Route {
|
|
#[route("/")]
|
|
Home {},
|
|
#[route("/blog/:id")]
|
|
Blog { id: i32 },
|
|
}
|
|
|
|
fn main() {
|
|
dioxus::launch(App);
|
|
}
|
|
|
|
#[component]
|
|
fn App() -> Element {
|
|
rsx! {
|
|
Router::<Route> {}
|
|
}
|
|
}
|
|
|
|
// We use id: ReadOnlySignal<i32> instead of id: i32 to make id work with reactive hooks
|
|
// Any i32 we pass in will automatically be converted into a ReadOnlySignal<i32>
|
|
#[component]
|
|
fn Blog(id: ReadOnlySignal<i32>) -> Element {
|
|
async fn future(n: i32) -> i32 {
|
|
n
|
|
}
|
|
|
|
// Because we accept ReadOnlySignal<i32> instead of i32, the resource will automatically subscribe to the id when we read it
|
|
let res = use_resource(move || future(id()));
|
|
|
|
match res() {
|
|
Some(id) => rsx! {
|
|
div {
|
|
"Blog post {id}"
|
|
}
|
|
for i in 0..10 {
|
|
div {
|
|
Link { to: Route::Blog { id: i }, "Go to Blog {i}" }
|
|
}
|
|
}
|
|
},
|
|
None => rsx! {},
|
|
}
|
|
}
|
|
|
|
#[component]
|
|
fn Home() -> Element {
|
|
rsx! {
|
|
Link {
|
|
to: Route::Blog {
|
|
id: 0
|
|
},
|
|
"Go to blog"
|
|
}
|
|
}
|
|
}
|