Custom Hooks in React
15 questions · 12 min · Medium
Test your knowledge of handling events in React, including event handlers, Synthetic Events, event arguments, forms, and common React event patterns.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. onClick
React uses camelCase event props such as onClick to handle click events.
C. onClick={handleClick}
Passing the function reference allows React to call it when the event occurs.
A. onChange
The onChange event is commonly used to respond to changes in form input values.
B. The event object
React passes an event object to the event handler containing information about the event.
C. event.target.value
event.target refers to the element that triggered the event, and value contains its current value.
B. preventDefault()
Calling event.preventDefault() prevents the browser's default action for that event.
B. stopPropagation()
stopPropagation() prevents the event from continuing through the event propagation path.
A. Names should usually start with handle
A common convention is to name event handlers with a handle prefix, such as handleClick or handleSubmit.
B. onSubmit
The onSubmit event is attached to a form to handle its submission.
B. A wrapper around the browser's native event
React provides a normalized event interface around native browser events.
B. onClick={() => handleClick(id)}
An arrow function can be used to call the handler with the desired argument when the event occurs.
A. The function is generally called during rendering
Adding parentheses calls the function immediately while rendering instead of passing the function as an event handler.
C. onChange
Checkboxes commonly use onChange, with the checked property used to determine whether the checkbox is selected.
A. value and onChange
A controlled input receives its value from React state and updates that state through an onChange handler.
B. React event names use camelCase such as onClick
React event props use camelCase naming, such as onClick, onChange, onSubmit, and onMouseEnter.