Skip to content

Instantly share code, notes, and snippets.

@cbilgili
Created January 23, 2016 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbilgili/89cab4196a6018daef26 to your computer and use it in GitHub Desktop.
Save cbilgili/89cab4196a6018daef26 to your computer and use it in GitHub Desktop.
React Trix Editor
class TrixEditor extends React.Component {
propTypes: {
value: PropTypes.string,
onChange: PropTypes.func
}
componentDidMount () {
this.trix = ReactDOM.findDOMNode(this)
this.changeListener = document.addEventListener(
'trix-change', this.onChange.bind(this))
this.trix.editor.insertHTML(this.props.value)
}
componentWillDismount () {
this.changeListener()
}
onChange (event) {
if (event.target === this.trix) {
this.props.onChange(event)
}
}
render () {
return (
<trix-editor {...this.props}></trix-editor>
)
}
}
<TrixEditor value={this.props.tour_day.description} onChange={this.onTrixChanged} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment