0

Have a simple search bar (input field) which should trigger an onSubmit action while we press Enter button

AB Dev
  • 11
  • 1
  • use onKeyPress: https://stackoverflow.com/questions/27827234/how-to-handle-the-onkeypress-event-in-reactjs – Joey Apr 12 '22 at 14:55

2 Answers2

0

You can use onKeyPress. Check this : https://stackoverflow.com/questions/13987300/how-to-capture-enter-key-press

yanir midler
  • 2,153
  • 1
  • 4
  • 16
0

Simple, have a button type submit inside the form. Here's an example:

const onSubmit = () => {}
// ..
<form onSubmit={onSubmit}>
  ...
  <button type="submit">Search</button>
  ...
</form>

You don't need to use onKeyPress event.

Vijay Dev
  • 1,024
  • 7
  • 14