event handler

A function that runs when something happens to an element, such as a click (onClick) or a key press (onKeyDown).

In more detail

When a component merges its own handler with a consumer's, it should call both, usually the consumer's first, and skip its own if the consumer called event.preventDefault(). Replacing one with the other silently breaks behaviour.

Example

<button onClick={() => setOpen(true)}>Open</button>

Related terms

Taught in

References