Event Parameters

Last updated: 2026-11-02

Event Parameters Event Parameters

An event handler receives the event object e and can read values such as target.value or key from it. When extra arguments have to be passed along, wrap the call in an arrow function — onClick={() => fn(id)} — because writing fn(id) would execute it while rendering. React 17 also stopped pooling event objects, so you can safely keep one around and read it later.

GroupRendering & State
KindPattern
SinceEarliest React versions

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

onChange={(e) => setName(e.target.value)}  // e: the event object
onClick={() => remove(id)}                 // Extra arguments: wrap in an arrow function
onClick={(e) => remove(id, e)}             // Both the arguments and the event object

⚙️ Parameters

e (event object)The React synthetic event object; e.target.value reads the current value of an input and e.type tells you which event fired.

Returns:No return value — a coding convention and mental model.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

Three color swatch buttons; clicking one records "Picked #xxxxxx (event type: click)" below, newest first and at most three entries — a demonstration of passing custom arguments to an event handler.

💡 Key Points

💡 Tip Write () => fn(x) to pass arguments; writing fn(x) directly runs it while rendering — the most common bug when passing event arguments.
ℹ️ Info The properties you read most often are e.target.value (the current value of an input) and e.key (which key was pressed in a keyboard event).
ℹ️ Info Since React 17 event objects are no longer pooled, so you can safely store one or read it asynchronously without calling e.persist().
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q How do I pass arguments to onClick?
A Wrap the call in an arrow function: onClick={() => remove(id)}; if you also need the event object, write onClick={(e) => remove(id, e)}.
Q Which event object properties do I use most?
A e.target (the element that fired the event, often combined with .value to read an input), e.type (the event type), e.key (the keyboard key) and e.clientX/Y (the mouse position).
Q Should I use arrow functions or bind to pass arguments?
A Modern code uses arrow functions everywhere; they are clearer to read. bind is the older approach with the same effect but worse readability, so new projects do not need it.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏