1
0

hydration.rs 1.0 KB

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