mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-19 00:53:12 +00:00
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
#![allow(non_snake_case)]
|
|
use dioxus::prelude::*;
|
|
use dioxus_fullstack::prelude::*;
|
|
|
|
pub fn app(cx: Scope) -> Element {
|
|
let mut count = use_state(cx, || 0);
|
|
let text = use_state(cx, || "...".to_string());
|
|
|
|
cx.render(rsx! {
|
|
h1 { "High-Five counter: {count}" }
|
|
button { onclick: move |_| count += 1, "Up high!" }
|
|
button { onclick: move |_| count -= 1, "Down low!" }
|
|
button {
|
|
onclick: move |_| {
|
|
to_owned![text];
|
|
async move {
|
|
if let Ok(data) = get_server_data().await {
|
|
println!("Client received: {}", data);
|
|
text.set(data.clone());
|
|
post_server_data(data).await.unwrap();
|
|
}
|
|
}
|
|
},
|
|
"Run a server function"
|
|
}
|
|
"Server said: {text}"
|
|
})
|
|
}
|
|
|
|
#[server(PostServerData)]
|
|
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
|
|
println!("Server received: {}", data);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[server(GetServerData)]
|
|
async fn get_server_data() -> Result<String, ServerFnError> {
|
|
Ok("Hello from the server!".to_string())
|
|
}
|