Files
dioxus/packages/playwright-tests/fullstack/src/main.rs
T
Evan Almloff 176e67e5b7 switch to a Document trait and introduce Script/Head/Style/Meta components (#2635)
* switch to a Document trait and introduce Script/Head/Style/Meta components

* Fix desktop title

* Insert special elements into the head during the inital SSR render

* Make all head component attributes optional

* hydrate head elements

* improve the server streaming head warning

* Document fullstack head hydration approach

* deduplicate head elements by href

* move Link into head::Link

* document head components

* add meta and title examples

* Fix a few doc examples

* fix formatting

* Add title to playwright tests

* serde is optional on web, but it is enabled by hydrate

* remove leftover console log
2024-07-17 20:54:03 -05:00

48 lines
1.2 KiB
Rust

// This test is used by playwright configured in the root of the repo
// Tests:
// - Server functions
// - SSR
// - Hydration
#![allow(non_snake_case)]
use dioxus::prelude::*;
fn main() {
LaunchBuilder::fullstack().launch(app);
}
fn app() -> Element {
let mut count = use_signal(|| 12345);
let mut text = use_signal(|| "...".to_string());
rsx! {
h1 { "hello axum! {count}" }
Title { "hello axum! {count}" }
button { class: "increment-button", onclick: move |_| count += 1, "Increment" }
button {
class: "server-button",
onclick: move |_| async move {
if let Ok(data) = get_server_data().await {
println!("Client received: {}", data);
text.set(data.clone());
post_server_data(data).await.unwrap();
}
},
"Run a server function!"
}
"Server said: {text}"
}
}
#[server(PostServerData)]
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
println!("Server received: {}", data);
Ok(())
}
#[server(GetServerData)]
async fn get_server_data() -> Result<String, ServerFnError> {
Ok("Hello from the server!".to_string())
}