Skip to content
Advertisement

React.js: onChange event for contentEditable

How do I listen to change events for a contentEditable-based control?

JavaScript

Code on JSFiddle.

Advertisement

Answer

See Sebastien Lorber’s answer which fixes a bug in my implementation.


Use the onInput event, and optionally onBlur as a fallback. You might want to save the previous contents to prevent sending extra events.

I’d personally have this as my render function.

JavaScript

jsbin

Which uses this simple wrapper around contentEditable.

JavaScript
Advertisement