From 438594bb2a1838db7d05ae9fdd37adc3ec2ac492 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Thu, 6 Oct 2022 21:22:44 -0400 Subject: Test server communication --- webapp/src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'webapp/src/main.rs') diff --git a/webapp/src/main.rs b/webapp/src/main.rs index 8a1fccc..8b77ea2 100644 --- a/webapp/src/main.rs +++ b/webapp/src/main.rs @@ -5,6 +5,7 @@ pub mod bridge_engine; pub mod card; pub mod components; use components::Game; +use gloo_net::http::Request; extern crate wee_alloc; // Use `wee_alloc` as the global allocator. @@ -19,8 +20,30 @@ fn main() { #[function_component(App)] pub fn app() -> Html { + let msg = use_state(|| "".to_string()); + { + let msg = msg.clone(); + use_effect_with_deps( + move |_| { + wasm_bindgen_futures::spawn_local(async move { + msg.set( + Request::get("/api/test") + .send() + .await + .unwrap() + .json() + .await + .unwrap(), + ) + }); + || () + }, + (), + ) + } html! { <> +

{ &*msg }

-- cgit v1.2.3