amis sdk里面使用可视化编辑器报错

6bc51xsx  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(79)
const React = amisRequire('react');
import { Editor } from 'amis-editor';

const amis = amisRequire('amis');

const schemaUrl = `${window.location.pathname}/schema.json`;

export class VisualeditorControl extends React.Component{
  constructor(props) {
    super(props);
  }

  onChange = ()=>{}

  render() {
    return <div className="visual-editor">
      <Editor
        preview={false}
        isMobile={true}
        value={{
          type: 'page',
          body: 'xxxx',
        }}
        onChange={this.onChange}
        $schemaUrl={schemaUrl}
        showCustomRenderersPanel={false}
        autoFocus={true}
         />
    </div>;
  }
}

@amis.Renderer({ test: /(^|\/)visual-editor/})
export default class VisualeditorControlRenderer extends VisualeditorControl {}

渲染:

const amis = amisRequire('amis/embed');

amis.embed('#root', {
  type: 'page',
  title: '表单页面',
  body: {
    type: 'form',
    body: [
      {
        label: 'visual-editor',
        type: 'visual-editor', 
        name: 'custom'
      }
    ]
  }
});

在设计器中预览没有问题,注册到sdk上就报错了,sdk版本6.3.0、6.5.0都试过了。

报错内容:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
kmbjn2e3

kmbjn2e31#

👍 Thanks for this!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

相关问题