error_handle.rs 686 B

1234567891011121314151617181920212223242526272829303132333435
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus_desktop::launch(App);
  4. }
  5. #[component]
  6. fn App(cx: Scope) -> Element {
  7. let val = use_state(cx, || "0.0001");
  8. let num = match val.parse::<f32>() {
  9. Err(_) => return cx.render(rsx!("Parsing failed")),
  10. Ok(num) => num,
  11. };
  12. cx.render(rsx! {
  13. h1 { "The parsed value is {num}" }
  14. button {
  15. onclick: move |_| val.set("invalid"),
  16. "Set an invalid number"
  17. }
  18. (0..5).map(|i| rsx! {
  19. DemoC { x: i }
  20. })
  21. })
  22. }
  23. #[component]
  24. fn DemoC(cx: Scope, x: i32) -> Element {
  25. cx.render(rsx! {
  26. h1 {
  27. "asdasdasdasd {x}"
  28. }
  29. })
  30. }