mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-28 07:00:19 +00:00
33 lines
733 B
Rust
33 lines
733 B
Rust
#![allow(non_snake_case)]
|
|
|
|
use dioxus::events::MouseData;
|
|
use dioxus::prelude::*;
|
|
|
|
fn main() {
|
|
dioxus_desktop::launch(App);
|
|
}
|
|
|
|
fn App(cx: Scope) -> Element {
|
|
// ANCHOR: usage
|
|
cx.render(rsx! {
|
|
FancyButton {
|
|
on_click: move |event| println!("Clicked! {event:?}")
|
|
}
|
|
})
|
|
// ANCHOR_END: usage
|
|
}
|
|
|
|
// ANCHOR: component_with_handler
|
|
#[derive(Props)]
|
|
pub struct FancyButtonProps<'a> {
|
|
on_click: EventHandler<'a, MouseData>,
|
|
}
|
|
|
|
pub fn FancyButton<'a>(cx: Scope<'a, FancyButtonProps<'a>>) -> Element<'a> {
|
|
cx.render(rsx!(button {
|
|
class: "fancy-button",
|
|
onclick: move |evt| cx.props.on_click.call(evt),
|
|
"click me pls."
|
|
}))
|
|
}
|
|
// ANCHOR_END: component_with_handler
|