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.
LIVE
onClick handler
Clicks:
onClick
let count = signal(0);
view! {
<button onClick={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 = signal(Vec::<String>::new());
view! {
<button onClick={js! {
// rs2js translates signal updates + action calls
state.results.set(["from server"]);
}}>
"Search"
</button>
}Multiple events
view! {
<input
onInput={ move |ev| name.set(ev) }
onKeyDown={ move |key| { /* ... */ } }
/>
}