Typing Events (Forms and Inputs)
Veeg om het menu te tonen
In React, events are used to handle user actions like typing or submitting forms. In TypeScript, you define what kind of event you are working with, so you can safely access its values.
Typing Input Change Event
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
console.log(event.target.value);
}
eventcomes from an<input>;valueis available and correctly typed. Using withinput:
<input onChange={handleChange} />
Typing Form Submit Event
function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
}
- used for form submission;
preventDefault()stops page reload.
Using with form:
<form onSubmit={handleSubmit}>
<button type="submit">Submit</button>
</form>
Type events based on the element they come from, so you can safely access their properties.
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 27
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Sectie 1. Hoofdstuk 27