codify "platform" into resolution logic, server-fn/fullstack overhaul (#4596)
overhaul dioxus fullstack using a new implementation of server_fn This PR is a complete rewrite of dioxus fullstack designed to improve compatibility with axum and to fix a number of compilation errors based on feature flag unification plumbing through macros.
This commit is contained in:
1 parent
8421c3aef0
commit
f2b1c6d97f
424 files changed
+17284
-6624
No files matched your search
@@ -0,0 +1,64 @@
|
||||
//! Example: Updating components with use_resource
|
||||
//! -----------------
|
||||
//!
|
||||
//! This example shows how to use ReadSignal 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: ReadSignal<i32> instead of id: i32 to make id work with reactive hooks
|
||||
// Any i32 we pass in will automatically be converted into a ReadSignal<i32>
|
||||
#[component]
|
||||
fn Blog(id: ReadSignal<i32>) -> Element {
|
||||
async fn future(n: i32) -> i32 {
|
||||
n
|
||||
}
|
||||
|
||||
// Because we accept ReadSignal<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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user