Have built a chat feature in React.js. It works but the page is reloaded when sending the message. Better to be able to send a chat when pressing the enter, but it should not be reloaded. How can the app works to send a message with enter without reloading.
<form>
<input
name="chat"
type="text"
placeholder="Enter message"
value={this.state.chat}
onChange={this.handleChange}
/>
<button
onClick={() => this.handleSend(chat)}
>
<span>Send</span>
</button>
</form>
If I don't use <form />
, it won't be reloaded. But it doesn't work to send a message when pressing the enter.