mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 14:44:12 +00:00
remove ws message logging
This commit is contained in:
parent
579da12ab6
commit
a9375af2b4
3 changed files with 39 additions and 1 deletions
35
docs/guide/examples/hydration_props.rs
Normal file
35
docs/guide/examples/hydration_props.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
#![allow(non_snake_case, unused)]
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
#[cfg(feature = "web")]
|
||||
dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true));
|
||||
#[cfg(feature = "ssr")]
|
||||
{
|
||||
use dioxus_fullstack::prelude::*;
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async move {
|
||||
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
axum::Server::bind(&addr)
|
||||
.serve(
|
||||
axum::Router::new()
|
||||
.connect_hot_reloading()
|
||||
.serve_dioxus_application("", ServeConfigBuilder::new(app, ()))
|
||||
.into_make_service(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let mut count = use_state(cx, || 0);
|
||||
|
||||
cx.render(rsx! {
|
||||
h1 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
})
|
||||
}
|
|
@ -82,6 +82,10 @@ Next, we need to modify our `main.rs` to use either hydrate on the client or ren
|
|||
|
||||
Now, build your client-side bundle with `dioxus build --features web` and run your server with `cargo run --features ssr`. You should see the same page as before, but now you can interact with the buttons!
|
||||
|
||||
## Sycronizing props between the server and client
|
||||
|
||||
Lets make the initial count of the counter dynamic based on the current page.
|
||||
|
||||
## Communicating with the server
|
||||
|
||||
`dixous-server` provides server functions that allow you to call an automatically generated API on the server from the client as if it were a local function.
|
||||
|
|
|
@ -79,7 +79,6 @@ impl SSRState {
|
|||
// on initial page load connect to the disconnect ws
|
||||
const ws = new WebSocket(url);
|
||||
// if we disconnect, start polling
|
||||
ws.onmessage = (m) => {console.log(m)};
|
||||
ws.onclose = reload_upon_connect;
|
||||
})()"#;
|
||||
|
||||
|
|
Loading…
Reference in a new issue