Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Uncaught TypeError: props.getEditorState is not a function while using the separatorButton #186

Open
BlastWind opened this issue Sep 27, 2019 · 1 comment

Comments

@BlastWind
Copy link

Here's my setup:


import { Editor, createEditorState, AtomicBlock } from "medium-draft";

import { EditorState, AtomicBlockUtils } from "draft-js";
import { BLOCK_BUTTONS, INLINE_BUTTONS, ImageSideButton } from "medium-draft";
 ......

const sideButtons = [
  { title: "Image", component: ImageSideButton },
  { title: "Embed", component: SeparatorSideButton }
];

then in Render I would do <Editor sideButtons={sideButtons}/>

The ImageSideButton works perfectly, however, pressing the separator button will throw "props.getEditorState is not a function..." in a file named atomic.js

Here's the code for SeparatorSideButton, I copied it from your example.js:

class SeparatorSideButton extends React.Component {
  constructor(props) {
    super(props);
    this.onClick = this.onClick.bind(this);
  }

  onClick() {
    console.log(this.props);
    let editorState = this.props.getEditorState();
    const content = editorState.getCurrentContent();
    const contentWithEntity = content.createEntity(
      "separator",
      "IMMUTABLE",
      {}
    );
    const entityKey = contentWithEntity.getLastCreatedEntityKey();

    
    editorState = EditorState.push(
      editorState,
      contentWithEntity,
      "create-entity"
    );

    this.props.setEditorState(
      AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, "-")
    );

    this.props.close();
  }

  render() {
    return (
      <button
        className="md-sb-button md-sb-img-button"
        type="button"
        title="Add a separator"
        onClick={this.onClick}
      >
        <i className="fa fa-minus" />
      </button>
    );
  }
}

And it seems to be throwing from

this.props.setEditorState(
      AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, "-")
    );

Thanks in advance.
Annotation 2019-09-26 213206

@sahilpaudel
Copy link

Getting the same issue anyone will be looking into this one? @brijeshb42

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants