1
0

server_basic.rs 789 B

123456789101112131415161718192021222324252627282930
  1. #![allow(non_snake_case, unused)]
  2. use dioxus::prelude::*;
  3. #[tokio::main]
  4. async fn main() {
  5. #[cfg(feature = "ssr")]
  6. {
  7. use dioxus_fullstack::prelude::*;
  8. let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
  9. axum::Server::bind(&addr)
  10. .serve(
  11. axum::Router::new()
  12. .serve_dioxus_application("", ServeConfigBuilder::new(app, ()))
  13. .into_make_service(),
  14. )
  15. .await
  16. .unwrap();
  17. }
  18. }
  19. fn app(cx: Scope) -> Element {
  20. let mut count = use_state(cx, || 0);
  21. cx.render(rsx! {
  22. h1 { "High-Five counter: {count}" }
  23. button { onclick: move |_| count += 1, "Up high!" }
  24. button { onclick: move |_| count -= 1, "Down low!" }
  25. })
  26. }