Responding to events Flashcards
How can you handle events in a React component?
By passing a function as a prop to an element like <button>.</button>
What is the correct way to pass an event handler to an element?
onClick={handleClick}, not onClick={handleClick()}.
Where are event handler functions defined in a React component?
Inside a component.
What can event handler functions access?
Props.
How can you pass an event handler from a parent to a child component?
Declare an event handler in a parent and pass it as a prop to a child.
Can you define your own event handler props?
Yes, with application-specific names.
What happens to events in terms of propagation?
Events propagate upwards.
How can you prevent event propagation?
Call e.stopPropagation() on the first argument.
What should you call to prevent unwanted default browser behavior for events?
Call e.preventDefault().
What is a good alternative to propagation for calling an event handler?
Explicitly calling an event handler prop from a child handler.