Event Handlers
Closures in onClick and other event attributes are translated to JavaScript at compile time (rs2js in resuma-macros) and lazy-loaded on first interaction.
onClick
let count = use_signal(0);
view! {
<button onClick={ move |_| count.update(|c| *c += 1) }>
"+"
</button>
}How translation works
- view! captures the closure at compile time.
- rs2js (inside resuma-macros) emits a small JS module.
- SSR embeds a HandlerRef in
data-r-on:clickattributes. - On first click, the runtime fetches
/_resuma/handler/:chunkand runs the handler.
Calling server actions
let results = use_signal(Vec::<String>::new());
view! {
<button onClick={ move |_| {
// rs2js translates signal updates + action calls
results.set(vec!["from server".into()]);
}}>
"Search"
</button>
}Multiple events
view! {
<input
onInput={ move |ev| name.set(ev) }
onKeyDown={ move |key| { /* ... */ } }
/>
}