Quiz
This quiz is an opportunity to test your knowledge on creating strongly-typed events and event handlers.
Creating strongly-typed events and event handlers
1
We have an input
HTML element in a components JSX:
<input type="text" />
How can we add a strongly-typed event handler to the input
for the keydown
event, to output the keys pressed to the console.
A)
<input type="text" onKeyDown={e=>console.log(e.key)} />
B)
<input type="text" onKeyDown={e:React.KeyboardEvent<HTMLInputElement> => console.log(e.key)} />
C)
<input type="text" onKeyDown={(e: React.KeyboardEvent) => console.log(e.key)} />
Question 1 of 30 attempted
Get hands-on with 1400+ tech skills courses.