* feat: integrate dioxus-logger inline * remove log/simple logger references * fix: add dioxus-data-id-0 to root elements to not emit errors internally * drop config.toml and use cargo.toml profiles instead * make clippy happy with the unit value lint * feat: better presentation for logging
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
//! Run with:
|
|
//!
|
|
//! ```sh
|
|
//! dx serve --platform web
|
|
//! ```
|
|
|
|
#![allow(non_snake_case, unused)]
|
|
use dioxus::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
fn app() -> Element {
|
|
let mut count = use_signal(|| 0);
|
|
let mut text = use_signal(|| "...".to_string());
|
|
let server_future = use_server_future(get_server_data)?;
|
|
|
|
rsx! {
|
|
document::Link { href: asset!("/assets/hello.css"), rel: "stylesheet" }
|
|
h1 { "High-Five counter: {count}" }
|
|
button { onclick: move |_| count += 1, "Up high!" }
|
|
button { onclick: move |_| count -= 1, "Down low!" }
|
|
button {
|
|
onclick: move |_| 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]
|
|
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
|
|
println!("Server received: {}", data);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[server]
|
|
async fn get_server_data() -> Result<String, ServerFnError> {
|
|
Ok(reqwest::get("https://httpbin.org/ip").await?.text().await?)
|
|
}
|
|
|
|
fn main() {
|
|
dioxus::launch(app);
|
|
}
|