React Event System Lab
Overview
In this lab you'll respond to events in React and write event handlers.
Keypad
Mr. Burns has requested us to build a new keypad component for the nuclear
plant, since the last one was way too complicated for his employees to use.
We'll keep things super simple instead, and use an <input type="password" />
field to capture input. Here's how to complete the exercise:
- In the
components/Keypad.js
file, create aKeypad
React component. - In that component, render an
input
with the right type. - On that
input
, add an event handler that listens for thekeyUp
event. - When that event fires, use
console.log
to print out the text'Entering password...'
.
Eyes on the ball
Let's say you're in the club with your buddy. The music's blaring, lights are flashing... It's so hard to get his attention! Your job is to create a component that registers whenever he focuses on you, and when his eyes are drifting off.
- In the
components/EyesOnMe.js
file, create aEyesOnMe
React component. - In that component, render a
button
. - On that
button
, add event handlers that listens for thefocus
andblur
events. - When the
focus
event fires, useconsole.log
to print out the text'Good!'
. - When the
blur
event fires, useconsole.log
to print out the text'Hey! Eyes on me!'
.