Event Parameters and Data
Often you need to pass additional data to event handlers beyond the event object itself. Let's explore patterns for handling data in events.
Passing Parameters to Handlers
There are several ways to pass data to event handlers:
Loading React playground...
Reading Event Data
Event handlers can read data from the event object:
Loading React playground...
Keyboard Events
Handling keyboard input with key information:
Loading React playground...
Data Attributes
Using data attributes to pass information:
Loading React playground...
Exercise: Parameter Passing
Loading exercise...
Exercise: Event Data Extraction
Loading exercise...
Exercise: Keyboard Handler
Loading exercise...
Key Takeaways
- Arrow wrapper -
onClick={() => handler(data)}for inline params - Handler factory -
onClick={createHandler(data)}for reusable handlers - Event target - Access input values via
event.target.value - Dataset - Use
data-*attributes for custom data - Keyboard events - Check
key,ctrlKey,shiftKey, etc.

