1
0

event_handler_prop.rs 703 B

1234567891011121314151617181920212223242526272829303132
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. fn main() {
  4. dioxus_desktop::launch(App);
  5. }
  6. fn App(cx: Scope) -> Element {
  7. // ANCHOR: usage
  8. cx.render(rsx! {
  9. FancyButton {
  10. on_click: move |event| println!("Clicked! {event:?}")
  11. }
  12. })
  13. // ANCHOR_END: usage
  14. }
  15. // ANCHOR: component_with_handler
  16. #[derive(Props)]
  17. pub struct FancyButtonProps<'a> {
  18. on_click: EventHandler<'a, MouseEvent>,
  19. }
  20. pub fn FancyButton<'a>(cx: Scope<'a, FancyButtonProps<'a>>) -> Element<'a> {
  21. cx.render(rsx!(button {
  22. class: "fancy-button",
  23. onclick: move |evt| cx.props.on_click.call(evt),
  24. "click me pls."
  25. }))
  26. }
  27. // ANCHOR_END: component_with_handler