dioxus/examples/external_updates.rs
2021-05-17 17:59:10 -04:00

38 lines
906 B
Rust

//! Example: External Updates
//! -------------------------
//! Cause updates to the VirtualDOM state from outside the component lifecycle.
//! The root props could be changed or the use_receiver hook could be used.
//!
//!
fn main() {
let (recv, sender) = channel();
async_std::task::spawn({
for location in ["a", "b", "c", "d"] {
sender.send(location);
}
});
let app = diouxs_webview::launch_with_props(App, RootProps { recv }).await;
}
struct RootProps {
navigator: Receiver<&'static str>,
}
fn App(ctx: Context, props: &RootProps) -> DomTree {
let router = use_router(&ctx, |router| {});
let navigator = use_history(&ctx);
use_receiver(&ctx, || props.recv.clone(), |to| navigator.navigate(to));
ctx.render(rsx! {
div {
a { href="/dogs/"}
a { href="/cats/"}
{content}
}
})
}