dioxus/packages/liveview/examples/axum.rs

31 lines
665 B
Rust
Raw Normal View History

use axum::Router;
use dioxus::prelude::*;
use dioxus_liveview::LiveviewRouter;
fn app() -> Element {
2024-01-13 21:12:21 -08:00
let mut num = use_signal(|| 0);
2024-01-13 21:12:21 -08:00
rsx! {
div {
"hello axum! {num}"
button { onclick: move |_| num += 1, "Increment" }
}
2024-01-13 21:12:21 -08:00
}
}
2022-04-23 22:13:43 -04:00
#[tokio::main]
async fn main() {
pretty_env_logger::init();
2022-04-23 22:13:43 -04:00
let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
2022-04-23 22:13:43 -04:00
let app = Router::new().with_app("/", app);
2023-01-27 20:35:46 -06:00
println!("Listening on http://{addr}");
2024-02-15 18:59:57 -08:00
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
2022-04-23 22:13:43 -04:00
}