Coding task · JavaScript and React course · Module 3: State and Events
Practice: onClick, onMouseEnter and onKeyDown
One element can have several event handlers at once. The event object e tells you what happened - e.g. e.key holds the name of the pressed key.
Task
Create an EmergencyAlert component with a message state shown in a <p> paragraph and render it in App. Add an ALARM button: onClick sets the message 'Alarm activated!' and onMouseEnter sets 'Careful: cursor over the alarm button'. Also add an <input> field with onKeyDown that sets 'Alarm triggered from the keyboard' when Enter is pressed (e.key === 'Enter') and ignores other keys.