Menangkap Enter di JavaScript

//You can use onKeyPress directly on input field. onChange function changes 
//state value on every input field change and after Enter
//is pressed it will call a function search().

<input
    type="text"
    placeholder="Search..."
    onChange={event => {this.setState({query: event.target.value})}}
    onKeyPress={event => {
                if (event.key === 'Enter') {
                  this.search()
                }
              }}
/>
Poised Porpoise