Feat: about to consolidate context and scope
This commit is contained in:
1 parent
3de54d0b52
commit
4c8130c4e4
5 files changed
+136
-9
No files matched your search
@@ -0,0 +1,38 @@
|
||||
//! 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}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user