dioxus/examples/eval.rs
Jonathan Kelley dd4547d753
Feat: add global context functions
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.
2023-10-23 16:26:10 -04:00

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" }
)),
}
}