It is very simple in react, you can add any key event listener. I have used example of "Enter".
I have defined a sample function for the explaination.
    const handleInputEnter = (e) => {
        // You can 
        if(e.code === 'Enter') {
            console.log("Hello");
        }
    }
Add onKeyUp attribute in the element.
Example:
<input type="text" onKeyUp={handleInputEnter}  />
This will work completely fine.
Follow me on twitter: https://twitter.com/vedantj_03
    
Top comments (0)