error_handle.rs 467 B

12345678910111213141516171819202122
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus_desktop::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let val = use_state(&cx, || "0.0001");
  7. let num = match val.parse::<f32>() {
  8. Err(_) => return cx.render(rsx!("Parsing failed")),
  9. Ok(num) => num,
  10. };
  11. cx.render(rsx! {
  12. h1 { "The parsed value is {num}" }
  13. button {
  14. onclick: move |_| val.set("invalid"),
  15. "Set an invalid number"
  16. }
  17. })
  18. }