This commit is contained in:
2025-06-30 12:19:17 -05:00
parent c2a3899fe1
commit 915dabe9e2
17 changed files with 773 additions and 1 deletions
@@ -0,0 +1,24 @@
---
title: Handler
---
A `Handler` is a closure wrapper. Due to how closures work, they aren't the best to work with on structs (in this case: elements). So to fix this we use a `Handler` which is a wrapper for the closure, Then you can safely clone and use it without any problems (in which a normal closure would fail at)
## Examples
```rust
Handler::new(|btn: &mut Button, event, document| {
// do something
})
```
A better way to do this is:
```rust
rsx! {
button {
// No need for Handler::new
on_click: fn(btn: &mut Button, event, document) {
// do something
}
}
}
```
> :::info `fn() {}` is a part of our macro `rsx!`. In rust you would normally use `|| {}`