Quiz
Test your understanding of creating strongly-typed component events and event handlers in React using TypeScript. This quiz helps reinforce key concepts for building robust and maintainable applications before progressing to typing React context.
We'll cover the following...
We'll cover the following...
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)} />
1 / 3
Great stuff! ...