add a desktop eval example

This commit is contained in:
Ilya Maximov 2022-03-19 03:11:30 +01:00
parent 40869b36ad
commit 5e475fadd9
No known key found for this signature in database
GPG key ID: 1ACCDCC0429C9737

25
examples/eval.rs Normal file
View file

@ -0,0 +1,25 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let script = use_state(&cx, String::new);
let eval = use_eval(&cx);
cx.render(rsx! {
div {
input {
placeholder: "Enter an expression",
value: "{script}",
oninput: move |e| script.set(e.value.clone()),
}
button {
onclick: move |_| eval(script),
"Execute"
}
}
})
}