Open AlexandraOM opened 4 years ago
Yeah generally you want to listen for the submit event on the form element
<form
onSubmit={e => {
e.preventDefault(); // stops the form doing an actual request and refreshing the page
}
/>
This is generally a nicer experience because the user can hit enter inside the text input to submit the form. Not everyone explicitly clicks the button.
Also by default button elements inside of forms will submit the form (they default to type="submit"
). If you want a non-submit button inside a form (like your "start game" button) you need to explicitly give it type="button"
.
I don't know if the form was an issue for you guys, but we noticed it on another team's project too. If you put
onSubmit
into the form tags with the same code it works like a request too.The above code can also be executed all inside of a separate function (if you want to modularise out a bit more)