dioxus/examples/eval.rs

34 lines
907 B
Rust
Raw Normal View History

2022-03-19 03:11:30 +01:00
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
2022-03-19 03:11:30 +01:00
}
fn app(cx: Scope) -> Element {
let eval = dioxus_desktop::use_eval(cx);
2022-12-30 02:06:33 -05:00
let script = use_state(cx, String::new);
let output = use_state(cx, String::new);
2022-03-19 03:11:30 +01:00
cx.render(rsx! {
div {
2022-12-30 02:06:33 -05:00
p { "Output: {output}" }
2022-03-19 03:11:30 +01:00
input {
placeholder: "Enter an expression",
value: "{script}",
oninput: move |e| script.set(e.value.clone()),
}
button {
2022-12-08 10:44:56 -06:00
onclick: move |_| {
2022-12-30 02:06:33 -05:00
to_owned![script, eval, output];
cx.spawn(async move {
if let Ok(res) = eval(script.to_string()).await {
output.set(res.to_string());
}
});
2022-12-08 10:44:56 -06:00
},
2022-03-19 03:11:30 +01:00
"Execute"
}
}
})
}