v0.20.230 - 6.3 / 6

addEvent / removeEvent

Imperative event-listener helpers. Use them outside JSX (in effects, lifecycles, or standalone code) when you need DOM.addEventListener-like control but tied to the reactive scope.

# addEvent Arguments

Returns an off() function that removes the listener. The same removal is also registered as a cleanup on the current reactive scope, so the listener is torn down automatically when the scope is disposed — you don't have to call off() manually in most cases.

nametypedescription
nodenodereference to the node on which to add the event listener
typestringevent listener to add, example click. Types are case sensitive, as regular event listeners
handlerfn | {handleEvent:fn, once?:bool, passive?:bool, etc?:bool}handler to run once the event is triggered

# removeEvent Arguments

Returns a handy on function that uses no arguments, to add the event back

nametypedescription
nodenodereference to the node from which to remove the event listener
typestringevent listener to remove, example click. Types are case sensitive, as regular event listeners
handlerfn | {handleEvent:fn, once?:bool, passive?:bool, etc?:bool}reference to the handler that has been added using addEvent

# Snippet

# Test Events Listeners