mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-18 00:23:07 +00:00
dd4547d753
Add functions like window() and router() to allow dynamically grabbing global contexts without have to use the hook variants. Deprecates the existing hook variants to discourage folks from adding more noise to their codebases.
33 lines
737 B
Rust
33 lines
737 B
Rust
use dioxus::prelude::*;
|
|
|
|
fn main() {
|
|
dioxus_desktop::launch(app);
|
|
}
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
let future = use_future(cx, (), |_| async move {
|
|
let eval = eval(
|
|
r#"
|
|
dioxus.send("Hi from JS!");
|
|
let msg = await dioxus.recv();
|
|
console.log(msg);
|
|
return "hello world";
|
|
"#,
|
|
)
|
|
.unwrap();
|
|
|
|
eval.send("Hi from Rust!".into()).unwrap();
|
|
let res = eval.recv().await.unwrap();
|
|
println!("{:?}", eval.await);
|
|
res
|
|
});
|
|
|
|
match future.value() {
|
|
Some(v) => cx.render(rsx!(
|
|
p { "{v}" }
|
|
)),
|
|
_ => cx.render(rsx!(
|
|
p { "hello" }
|
|
)),
|
|
}
|
|
}
|