baidu / amis

前端低代码框架,通过 JSON 配置就能生成各种页面。
https://baidu.github.io/amis/
Apache License 2.0
16.48k stars 2.41k forks source link

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

Open wuf-Gavin opened 2 weeks ago

wuf-Gavin commented 2 weeks ago
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.
github-actions[bot] commented 2 weeks ago

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

Please review the labels and make any necessary changes.