React: getting started

Lesson 04 · 10 min

Events and a form without reloading

onClick gets a function. A form needs preventDefault, otherwise the page flashes and reloads.

10 minLesson 4 of 8Practice includedAsk AI on any point

In JSX a handler is a camelCase property: onClick, onChange, onSubmit. The value is a function, not a string. The browser still sends an event object. A form with onSubmit but without event.preventDefault() makes a GET to the current URL, and you lose state.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.