Create a React component that counts how many times a specific key (e.g., 'a') is pressed on the keyboard.
EasyProblem Statement
Create a React component that counts how many times a specific key (e.g., 'a') is pressed on the keyboard.
Sample Output
Key 'a' pressed: 0 (increases each time 'a' is pressed).
Limits
Time: 2s · Memory: 256 MB
Code Editor
Log in to submit00:00
Try your code in this preview. Submit marks it done.
import React, { useState, useEffect } from "react"; const KeyPressCounter = () => { const [count, setCount] = useState(0); useEffect(() => { const handleKeyPress = (event) => { // Increment the count if "a" is pressed }; // Add event listener return () => { // Cleanup event listener }; }, []); return <p>Key "a" pressed: {count}</p>; }; export default KeyPressCounter;