Zum Hauptinhalt springen

Basics

Why is it important to use the value attribute in inputs when using the onChange event?

The onChange event listens to changes (key strokes, clicks etc.) in the input field. Usually the input field is implemented in a form which, once submitted, sets some values in the state. The input value is used to match the value inside the input with those in state. So we have full control (controlled inputs). If we delete date from state with a setter function, the input field will be emptied as well.