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
+3
-1
@@ -1 +1,3 @@
|
||||
# Hello examples
|
||||
# Examples
|
||||
|
||||
Most of these examples are run through webview so you don't need the dioxus cli installed to preview the functionality. Anything labeled `_web` will need to be compiled with Dioxus CLI.
|
||||
@@ -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}
|
||||
}
|
||||
})
|
||||
}
|
||||
+32
-1
@@ -8,4 +8,35 @@
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
diouxs_webview::launch(App).run().await
|
||||
}
|
||||
|
||||
fn App(ctx: Context, props: &()) -> DomTree {
|
||||
let router = use_router(&ctx, |router| {
|
||||
//
|
||||
router.get("/dogs/:dogId/").render(|ctx, request| {
|
||||
rsx! {
|
||||
div {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/cats/:catId/").render(|ctx, request| {
|
||||
rsx! {
|
||||
div {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
a { href="/dogs/"}
|
||||
a { href="/cats/"}
|
||||
{router.render()}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user