Have a simple search bar (input field) which should trigger an onSubmit action while we press Enter button
You can use onKeyPress. Check this: https://stackoverflow.com/questions/13987300/how-to-capture-enter-key-press
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.