1234567891011121314151617181920212223242526272829303132333435363738 |
- //! 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}
- }
- })
- }
|