diff --git a/src/app.rs b/src/app.rs
index 5acd370..fb09c9b 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,4 +1,4 @@
-use leptos::prelude::*;
+use leptos::{prelude::*, task::spawn_local};
use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title};
use leptos_router::{
components::{Route, Router, Routes},
@@ -16,7 +16,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
-
+
@@ -38,7 +38,7 @@ pub fn App() -> impl IntoView {
// content for this welcome page
-
+
@@ -47,15 +47,28 @@ pub fn App() -> impl IntoView {
}
}
+/// Server-side increment function
+#[server]
+pub async fn increment(count: i32) -> Result {
+ Ok(count + 1) // Increment logic handled server-side
+}
+
/// Renders the home page of your application.
#[component]
fn HomePage() -> impl IntoView {
- // Creates a reactive value to update the button
+ // Client-side signal for count
let count = RwSignal::new(0);
- let on_click = move |_| *count.write() += 1;
+
+ // Button click handler to call the server function
+ let on_click = move |_| {
+ let count_value = count.get();
+ spawn_local(async move { count.set(increment(count_value).await.unwrap()) });
+ };
view! {
- "Welcome to Leptos!"
-
+ "Welcome to Leptos!"
+
}
}