DioxusLabs / DioxusLabs/dioxus

Dynamic optional event handlers

Open
#1,005 1 comment 5 reactions 0 assignees View on GitHub
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.