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

  1. view! captures the closure at compile time.
  2. rs2js (inside resuma-macros) emits a small JS module.
  3. SSR embeds a HandlerRef in data-r-on:click attributes.
  4. On first click, the runtime fetches /_resuma/handler/:chunk and 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| { /* ... */ } }
    />
}

See also

For complex client logic, use js! or #[server] actions.