fix other fullstack adapters

This commit is contained in:
Evan Almloff committed 2024-01-18 11:39:51 -06:00
1 parent 694bef0d93
commit 89b1e56fc3
9 files changed
+105 -95

No files matched your search

@@ -1,31 +1,17 @@
//! Run with:
//!
//! ```sh
//! dx build --features web --release
//! cargo run --features ssr --release
//! dx serve --platform fullstack
//! ```
#![allow(non_snake_case, unused)]
use dioxus::prelude::*;
use dioxus_fullstack::{launch, prelude::*};
use serde::{Deserialize, Serialize};
#[derive(Props, PartialEq, Debug, Default, Serialize, Deserialize, Clone)]
struct AppProps {
count: i32,
}
fn app(cx: Scope<AppProps>) -> Element {
let state =
use_server_future((), |()| async move { get_server_data().await.unwrap() })?.value();
fn app() -> Element {
let mut count = use_signal(|| 0);
let text = use_signal(|| "...".to_string());
rsx! {
div {
"Server state: {state}"
}
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
@@ -46,14 +32,14 @@ fn app(cx: Scope<AppProps>) -> Element {
}
}
#[server(PostServerData)]
#[server]
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
println!("Server received: {}", data);
Ok(())
}
#[server(GetServerData)]
#[server]
async fn get_server_data() -> Result<String, ServerFnError> {
Ok(reqwest::get("https://httpbin.org/ip").await?.text().await?)
}
@@ -64,5 +50,5 @@ fn main() {
#[cfg(feature = "ssr")]
tracing_subscriber::fmt::init();
LaunchBuilder::new_with_props(app, AppProps { count: 0 }).launch()
launch(app);
}