1
0

error_handle.rs 678 B

12345678910111213141516171819202122232425262728293031323334
  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. (0..5).map(|i| rsx! {
  18. demo_c { x: i }
  19. })
  20. })
  21. }
  22. #[inline_props]
  23. fn demo_c(cx: Scope, x: i32) -> Element {
  24. cx.render(rsx! {
  25. h1 {
  26. "asdasdasdasd {x}"
  27. }
  28. })
  29. }