event-delegation
Installation
SKILL.md
Event Delegation Pattern in React
Overview
Event delegation is a pattern where instead of attaching event handlers to individual child elements, you attach a single handler to a parent container. This eliminates the need to pass event handlers through props of all nested components.
When to use this skill
- Use when you render large lists or grids with many interactive elements.
- Use when you want to avoid prop drilling through deeply nested components.
- Use when content is dynamic (added or removed at runtime) and you need handlers to work without reattaching.
- Use when multiple similar elements share common behavior (for example: edit/delete/share actions per item).
- Use when you need a single point of control for consistent logging, analytics, or access control.
- Use when you want to reduce the number of event listeners for performance-sensitive UIs.
Core Principle
Instead of passing handlers through multiple levels of component props, attach a single event listener to a parent container and use event.target to identify which child element triggered the event.