Skip to content

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

Open
@wuf-Gavin

Description

@wuf-Gavin
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 {}
image image

渲染:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions