React-quill: Not compatible with Preact

Created on 14 Feb 2018  路  4Comments  路  Source: zenoamaro/react-quill

Hello, this is to be considered a feature request more than a bug.

Current version of react-quill doesn't work on a Preact environment (https://preactjs.com/)

Would it be possible to test and see what Preact is missing or react-quill is missing to make this work together? Thanks.

Most helpful comment

If you don't need the full declarative wrapper provided by React-Quill, you can create a "lite version" that simply instantiates Quill in a (P)React-provided DOM element like this:

/** @jsx h */
import { h, Component } from 'preact'
import { PropTypes } from 'react'
import Quill from 'quill'

class Editor extends Component {
  editorRef = null

  componentDidMount () {
    if (!this.editorRef) return;
    this.editor = new Quill(this.editorRef, {
      theme: this.props.theme,
      placeholder: this.props.placeholder,
    })
    // hook up change handlers...
  }

  shouldComponentUpdate (nextProps, nextState) {
    return false
  }

  render () {
    return <div ref={el => { this.editorRef = el }}/>
  }
}

Editor.propTypes = {
  placeholder: PropTypes.string,
  theme: PropTypes.oneOf(['snow', 'bubble']),
  onChange: PropTypes.func(),
}

Editor.defaultProps = {
  placeholder: '',
  theme: 'snow',
}

export default Editor

https://github.com/alexkrolick/electron-quill/blob/master/app/editor.jsx

All 4 comments

Looks like Preact is having issues with Mixins https://github.com/developit/preact-compat/issues/442

At some point the mixin and toolbar will be deprecated in favor of an ES6 rewrite. It'll be a breaking change but we can make sure it works with Preact at that point.

If you don't need the full declarative wrapper provided by React-Quill, you can create a "lite version" that simply instantiates Quill in a (P)React-provided DOM element like this:

/** @jsx h */
import { h, Component } from 'preact'
import { PropTypes } from 'react'
import Quill from 'quill'

class Editor extends Component {
  editorRef = null

  componentDidMount () {
    if (!this.editorRef) return;
    this.editor = new Quill(this.editorRef, {
      theme: this.props.theme,
      placeholder: this.props.placeholder,
    })
    // hook up change handlers...
  }

  shouldComponentUpdate (nextProps, nextState) {
    return false
  }

  render () {
    return <div ref={el => { this.editorRef = el }}/>
  }
}

Editor.propTypes = {
  placeholder: PropTypes.string,
  theme: PropTypes.oneOf(['snow', 'bubble']),
  onChange: PropTypes.func(),
}

Editor.defaultProps = {
  placeholder: '',
  theme: 'snow',
}

export default Editor

https://github.com/alexkrolick/electron-quill/blob/master/app/editor.jsx

This is exactly what I need. Thank you very much. Feel free to close this issue if the ES6 migration is being tracked somewhere else.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

InsectEater picture InsectEater  路  4Comments

Drejerdk picture Drejerdk  路  4Comments

stinoga picture stinoga  路  3Comments

Nazanin1369 picture Nazanin1369  路  4Comments

Fensterbank picture Fensterbank  路  3Comments