dioxus-websocket-hooks

Crates.iodioxus-websocket-hooks
lib.rsdioxus-websocket-hooks
version0.0.2
sourcesrc
created_at2022-01-10 07:51:44.147959
updated_at2022-01-15 12:20:58.547751
descriptionDioxus hooks for websocket connections
homepage
repositoryhttps://github.com/FruitieX/dioxus-websocket-hooks
max_upload_size
id511265
size39,258
Rasmus Lövegren (FruitieX)

documentation

README

dioxus-websocket-hooks

Dioxus hooks for websocket connections

use dioxus_websocket_hooks::{use_ws_context, use_ws_context_provider_json};

fn app(cx: Scope) -> Element {
    use_ws_context_provider_json(&cx, "wss://echo.websocket.events", move |msg| {
        // Handle incoming ws message, e.g. store it in shared state
    });

    ...
}

fn ExampleComponent(cx: Scope) -> Element {
    let ws = use_ws_context(&cx);

    cx.render(rsx! (
        button { onclick: move |_| ws.send_json(&"hello"), "Submit" }
    ))
}

Examples

See cargo examples

Samples make use of fermi for state management.

Commit count: 9

cargo fmt