React-draft-wysiwyg: Unknown DraftEntity key: null.

Created on 23 Jun 2020  ·  4Comments  ·  Source: jpuri/react-draft-wysiwyg

这是一个BUG,当我添加了一张图片之后,再输入一段中文,就报错了,输入英文字符就没有错

Most helpful comment

I followed the solution in this article.
ref: https://www.jianshu.com/p/52df009e6ec1
It works great for me.

You have to implement a custom image atom renderer.

  function myBlockRenderer(contentBlock) {
    const type = contentBlock.getType();

    // Convert image type to mediaComponent
    if (type === 'atomic') {
      return {
        component: MediaComponent,
        editable: false,
        props: {
          foo: 'bar',
        },
      };
    }
  }

  class MediaComponent extends React.Component {
    render() {
      const { block, contentState } = this.props;
      const { foo } = this.props.blockProps;
      const data = contentState.getEntity(block.getEntityAt(0)).getData();


      const emptyHtml = ' ';
      return (
        <div>
          {emptyHtml}
          <img
            src={data.src}
            alt={data.alt || ''}
            style={{height: data.height || 'auto', width: data.width || 'auto'}}
          />
        </div>
      );
    }
  }
 <Editor blockRendererFn={myBlockRenderer} />

All 4 comments

Also facing this issue

I followed the solution in this article.
ref: https://www.jianshu.com/p/52df009e6ec1
It works great for me.

You have to implement a custom image atom renderer.

  function myBlockRenderer(contentBlock) {
    const type = contentBlock.getType();

    // Convert image type to mediaComponent
    if (type === 'atomic') {
      return {
        component: MediaComponent,
        editable: false,
        props: {
          foo: 'bar',
        },
      };
    }
  }

  class MediaComponent extends React.Component {
    render() {
      const { block, contentState } = this.props;
      const { foo } = this.props.blockProps;
      const data = contentState.getEntity(block.getEntityAt(0)).getData();


      const emptyHtml = ' ';
      return (
        <div>
          {emptyHtml}
          <img
            src={data.src}
            alt={data.alt || ''}
            style={{height: data.height || 'auto', width: data.width || 'auto'}}
          />
        </div>
      );
    }
  }
 <Editor blockRendererFn={myBlockRenderer} />

thanks , It works great also for me .

thanks

Was this page helpful?
0 / 5 - 0 ratings