For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/apis/app/runtime/core/render.md.
  • 简体中文
  • render

    用于渲染项目组件。

    使用姿势

    import { render } from '@modern-js/runtime/browser';
    
    render(<ModernRoot />);

    函数签名

    export function render(
      App: React.ReactElement,
      id?: HTMLElement | string,
    ): Promise<any>;

    参数

    • App:通过 createRoot 创建的 ReactElement 实例。
    • id:要挂载的 DOM 根元素 id,如 "root"。

    示例

    import { createRoot } from '@modern-js/runtime/react';
    import { render } from '@modern-js/runtime/browser';
    
    const ModernRoot = createRoot();
    
    async function beforeRender() {
      // todo
    }
    
    beforeRender().then(() => {
      render(<ModernRoot />);
    });