Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

on enter key press react

onKeyPress={(e) => e.key === 'Enter' && handleSearch()}
Comment

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');
    }
  }
});
Comment

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);
    };
  }, []);
Comment

search to enter key react

class CartridgeShell extends React.Component {

   constructor(props) {
      super(props);
      this.state = {value:''}

      this.handleChange = this.handleChange.bind(this);
      this.keyPress = this.keyPress.bind(this);
   } 
 
   handleChange(e) {
      this.setState({ value: e.target.value });
   }

   keyPress(e){
      if(e.keyCode == 13){
         console.log('value', e.target.value);
         // put the login here
      }
   }

   render(){
      return(
         <input value={this.state.value} onKeyDown={this.keyPress} onChange={this.handleChange} fullWidth={true} />
      )
    }
}

ReactDOM.render(<CartridgeShell/>, document.getElementById('app'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: Send Form Data Using Ky AJAX 
Javascript :: javascript replace all string 
Javascript :: return an object from an array javascript 
Javascript :: react native password meter 
Javascript :: append after div 
Javascript :: decrement operator in javascript 
Javascript :: typescript react handle change 
Javascript :: preview image before upload reactjs 
Javascript :: compare two dates and sort array of objects 
Javascript :: react native navigation nested 
Javascript :: exec reges 
Javascript :: js check if string is int 
Javascript :: jquery 3.6.0 
Javascript :: javascript online test 
Javascript :: Svg as a component react 
Javascript :: make country flags in js 
Javascript :: make a file downloadable in react 
Javascript :: react dom cdn 
Javascript :: javascript crash course 
Javascript :: golang json omitempty struct 
Javascript :: json db 
Javascript :: javascript date format dd-mm-yyyy 
Javascript :: ipcrenderer main.js 
Javascript :: react styled functional component 
Javascript :: location.reload() js 
Javascript :: mongodb text search 
Javascript :: jquery get all classes of a div 
Javascript :: capture keystrokes in javascript 
Javascript :: disable input box javascript 
Javascript :: javscript match word in string 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =