eval.rs 554 B

123456789101112131415161718192021222324
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus_desktop::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let script = use_state(cx, String::new);
  7. let eval = dioxus_desktop::use_eval(cx);
  8. cx.render(rsx! {
  9. div {
  10. input {
  11. placeholder: "Enter an expression",
  12. value: "{script}",
  13. oninput: move |e| script.set(e.value.clone()),
  14. }
  15. button {
  16. onclick: move |_| eval(script.to_string()),
  17. "Execute"
  18. }
  19. }
  20. })
  21. }