1
0

hydration_props.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. .connect_hot_reloading()
  17. .serve_dioxus_application("", ServeConfigBuilder::new(app, ()))
  18. .into_make_service(),
  19. )
  20. .await
  21. .unwrap();
  22. });
  23. }
  24. }
  25. fn app(cx: Scope) -> Element {
  26. let mut count = use_state(cx, || 0);
  27. cx.render(rsx! {
  28. h1 { "High-Five counter: {count}" }
  29. button { onclick: move |_| count += 1, "Up high!" }
  30. button { onclick: move |_| count -= 1, "Down low!" }
  31. })
  32. }