sstur / react-rte

Pure React rich text WYSIWYG editor based on draft-js.
https://react-rte.org
ISC License
2.86k stars 430 forks source link

Cannot create property 'current' on string 'editor' #367

Open sebay00 opened 4 years ago

sebay00 commented 4 years ago

Hello,

I'm trying to add react-rte to my project, but I can't make it work. I'm using preact, and I'm trying to add a single component in my story book called RichText:

I copied the demo example and keep only what I need. It looks like this:

import React, { Component } from 'react';
import RichTextEditor, { createEmptyValue } from 'react-rte';
import autobind from 'class-autobind';

export default class RichText extends Component {
  constructor() {
    super(...arguments);
    autobind(this);
    this.state = {
      value: createEmptyValue(),
      readOnly: false,
    };
  }

  render() {
    let { value } = this.state;

    return (
      <div className="editor-demo">
        <div className="row">
          <RichTextEditor
            value={value}
            onChange={this._onChange}
            className="react-rte-demo"
            placeholder="Tell a story"
            toolbarClassName="demo-toolbar"
            editorClassName="demo-editor"
            readOnly={this.state.readOnly}
          />
        </div>
        <div className="row">
          <textarea
            className="source"
            placeholder="Editor Source"
            value={value.toString('html')}
            onChange={this._onChangeSource}
          />
        </div>
      </div>
    );
  }

  _onChange(value) {
    this.setState({ value });
  }

  _onChangeSource(event) {
    let source = event.target.value;
    let oldValue = this.state.value;
    this.setState({
      value: oldValue.setContentFromString(source, 'html'),
    });
  }
}

Can't make it work, the issue is something like : "Cannot create property 'current' on string 'editor'"

Please help