Answers for "check if enter key is pressed react"

11

on enter key press react

onKeyPress={(e) => e.key === 'Enter' && handleSearch()}
Posted by: Guest on February-16-2021
0

react detect enter key

var Input = React.createClass({
  render: function () {
    return <input type="text" onKeyDown={this._handleKeyDown} />;
  },
  _handleKeyDown: function(e) {
    if (e.key === 'Enter') {
      console.log('do validate');
    }
  }
});
Posted by: Guest on November-29-2020
2

on enter key press react js

useEffect(() => {
    const listener = event => {
      if (event.code === "Enter" || event.code === "NumpadEnter") {
        console.log("Enter key was pressed. Run your function.");
        event.preventDefault();
        // callMyFunction();
      }
    };
    document.addEventListener("keydown", listener);
    return () => {
      document.removeEventListener("keydown", listener);
    };
  }, []);
Posted by: Guest on June-09-2021

Code answers related to "check if enter key is pressed react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language