Last active
February 23, 2019 09:38
-
-
Save awebartisan/0fc4d05849105688c63d9ec8cae9b079 to your computer and use it in GitHub Desktop.
Adding event handler in Wysiwyg component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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