DioxusLabs / DioxusLabs/dioxus
Dynamic optional event handlers
Open
core
tweak
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Specific Demand
Just like we can pass `Option` to element attributes when we want to pass dynamic optional attribute, it should be possible to do the same withe event handlers.
That way, this would work:
```rust
#[derive(Props)]
struct ComponentProps<'a> {
#[props(optional)]
onclick: Option>
}
fn Component<'a>(cx: Scope<'a, ComponentProps<'a>>) -> Element<'a> {
let onclick = cx.props.onclick.map(|v| move |e| {
v.call(e);
});
render!(
div {
onclick: onclick
}
)
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.