Skip to content

Instantly share code, notes, and snippets.

@mikker
Created November 9, 2015 09:55
Show Gist options
  • Save mikker/8ace50104aa9b363ae03 to your computer and use it in GitHub Desktop.
Save mikker/8ace50104aa9b363ae03 to your computer and use it in GitHub Desktop.
Basecamp's Trix editor in a React component
import React, { Component, PropTypes } from 'react'
import { findDOMNode } from 'react-dom'
class TrixEditor extends Component {
static propTypes = {
value: PropTypes.string,
onChange: PropTypes.func
}
componentDidMount () {
this.trix = 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>
)
}
}
@cbilgili
Copy link

Thank you very much, I have updated something for my need at https://gist.github.com/cbilgili/89cab4196a6018daef26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment