1
0

main.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This test is used by playwright configured in the root of the repo
  2. // Tests:
  3. // - Server functions
  4. // - SSR
  5. // - Hydration
  6. #![allow(non_snake_case)]
  7. use dioxus::prelude::*;
  8. fn main() {
  9. LaunchBuilder::fullstack()
  10. .with_cfg(ssr! {
  11. dioxus::fullstack::Config::default().addr(std::net::SocketAddr::from(([127, 0, 0, 1], 3333)))
  12. })
  13. .launch(app);
  14. }
  15. fn app() -> Element {
  16. let mut count = use_signal(|| 12345);
  17. let mut text = use_signal(|| "...".to_string());
  18. rsx! {
  19. h1 { "hello axum! {count}" }
  20. button { class: "increment-button", onclick: move |_| count += 1, "Increment" }
  21. button {
  22. class: "server-button",
  23. onclick: move |_| async move {
  24. if let Ok(data) = get_server_data().await {
  25. println!("Client received: {}", data);
  26. text.set(data.clone());
  27. post_server_data(data).await.unwrap();
  28. }
  29. },
  30. "Run a server function!"
  31. }
  32. "Server said: {text}"
  33. }
  34. }
  35. #[server(PostServerData)]
  36. async fn post_server_data(data: String) -> Result<(), ServerFnError> {
  37. println!("Server received: {}", data);
  38. Ok(())
  39. }
  40. #[server(GetServerData)]
  41. async fn get_server_data() -> Result<String, ServerFnError> {
  42. Ok("Hello from the server!".to_string())
  43. }