ross
ross

Reputation: 105

React triggers onChange events for virtual DOM inputs differently than inputs in the regular DOM. Why is this?

In the virtual DOM, onChange is triggered every time the content of the input is changed. In the regular DOM, onChange is only triggered when the input element is blurred.

link to GIF illustrating the behavior

sample project:

source code for the above demo

Why does React trigger onChange events differently for virtual DOM elements?

Upvotes: 2

Views: 456

Answers (1)

Sophie Alpert
Sophie Alpert

Reputation: 143144

React DOM intentionally deviates and makes onChange fire on every change because that's almost always what you want. This is described in the documentation here: Forms.

Upvotes: 2

Related Questions