Skip to content

Instantly share code, notes, and snippets.

@awebartisan
Last active February 23, 2019 09:38
Show Gist options
  • Save awebartisan/0fc4d05849105688c63d9ec8cae9b079 to your computer and use it in GitHub Desktop.
Save awebartisan/0fc4d05849105688c63d9ec8cae9b079 to your computer and use it in GitHub Desktop.
Adding event handler in Wysiwyg component
import React, { Component } from "react";
import Trix from "trix";
class Wysiwyg extends React.Component {
constructor(props) {
super(props);
this.trixInput = React.createRef();
}
componentDidMount() {
this.trixInput.current.addEventListener("trix-change", event => {
console.log("trix change event fired");
this.props.onChange(event.target.innerHTML); //calling custom event
});
}
render() {
return (
<div>
<input type="hidden" id="trix" value={this.props.value} />
<trix-editor input="trix" ref={this.trixInput} />
</div>
);
}
}
export default Wysiwyg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment