Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: renderer-react #2706

Merged
merged 13 commits into from
Oct 19, 2023
Merged

feat: renderer-react #2706

merged 13 commits into from
Oct 19, 2023

Conversation

bravepg
Copy link
Contributor

@bravepg bravepg commented Sep 26, 2023

MicroApp 组件

直接通过 <MicroApp /> 组件加载(或卸载)子应用,该组件提供了 loading 以及错误捕获相关的能力:

import { MicroApp } from '@qiankunjs/react';

export default function Page() {
  return <MicroApp name="app1" entry="http://localhost:8000" />;
}

当启用子应用加载动画或错误捕获能力时,子应用接受一个额外的样式类 wrapperClassName,渲染的结果如下所示:

<div style={{ position: 'relative' }} className={wrapperClassName}>
  <MicroAppLoader loading={loading} />
  <ErrorBoundary error={e} />
  <MicroApp className={className} />
</div>

加载动画

启用此能力后,当子应用正在加载时,会自动显示加载动画。当子应用挂载完成变成 MOUNTED 状态时,加载状态结束,显示子应用内容。

直接将 autoSetLoading 作为参数传入即可:

import { MicroApp } from '@qiankunjs/react';

export default function Page() {
  return <MicroApp name="app1" entry="http://localhost:8000" autoSetLoading />;
}

自定义加载动画

如果您希望覆盖默认的加载动画样式时,可以设置一个自定义的加载组件 loader 作为子应用的加载动画。

import CustomLoader from '@/components/CustomLoader';
import { MicroApp } from '@qiankunjs/react';

export default function Page() {
  return (
    <MicroApp name="app1" entry="http://localhost:8000" loader={(loading) => <CustomLoader loading={loading} />} />
  );
}

其中,loadingboolean 类型参数,为 true 时表示仍在加载状态,为 false 时表示加载状态已结束。

错误捕获

启用此能力后,当子应用加载出现异常时,会自动显示错误信息。可以向子应用传入 autoCaptureError 属性以开启子应用错误捕获能力:

import { MicroApp } from '@qiankunjs/react';

export default function Page() {
  return <MicroApp name="app1" entry="http://localhost:8000" autoCaptureError />;
}

自定义错误捕获

如果您希望覆盖默认的错误捕获组件样式时,可以设置一个自定义的组件 errorBoundary 作为子应用的错误捕获组件:

import CustomErrorBoundary from '@/components/CustomErrorBoundary';
import { MicroApp } from '@qiankunjs/react';

export default function Page() {
  return (
    <MicroApp
      name="app1"
      entry="http://localhost:8000"
      errorBoundary={(error) => <CustomErrorBoundary error={error} />}
    />
  );
}

@changeset-bot
Copy link

changeset-bot bot commented Sep 26, 2023

⚠️ No Changeset found

Latest commit: b0ee024

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Sep 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
qiankun ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 2:34pm

Copy link
Member

@kuitos kuitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个项目需要补下 tsx 的 lint 规则,并继承自根目录的 eslint

packages/ui-bindings/react/README.md Show resolved Hide resolved
@kuitos
Copy link
Member

kuitos commented Oct 8, 2023

需要重新合并下主分支,应该是格式化后冲突了

@bravepg
Copy link
Contributor Author

bravepg commented Oct 8, 2023

需要重新合并下主分支,应该是格式化后冲突了

好的 我合并了

tsconfig.json Show resolved Hide resolved
@bravepg
Copy link
Contributor Author

bravepg commented Oct 12, 2023

@kuitos 啥时候有空帮我 review 下呀?因为 next 更新有点频繁,我需要一直 merge 👀

packages/ui-bindings/react/package.json Outdated Show resolved Hide resolved
packages/ui-bindings/react/README.md Outdated Show resolved Hide resolved
packages/ui-bindings/react/README.md Outdated Show resolved Hide resolved
packages/ui-bindings/react/README.md Outdated Show resolved Hide resolved
packages/ui-bindings/react/src/MicroApp.tsx Outdated Show resolved Hide resolved
packages/ui-bindings/react/src/MicroApp.tsx Outdated Show resolved Hide resolved
packages/ui-bindings/react/src/MicroApp.tsx Outdated Show resolved Hide resolved
packages/ui-bindings/react/src/MicroApp.tsx Outdated Show resolved Hide resolved
packages/ui-bindings/react/src/MicroApp.tsx Outdated Show resolved Hide resolved
packages/ui-bindings/react/src/MicroApp.tsx Outdated Show resolved Hide resolved
.eslintrc.cjs Show resolved Hide resolved
container: document.querySelector('#subapp-container'),
},
{ sandbox: true },
ReactDOM.render(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里先不改吧,MicroApp 应该是有单独的 react 版本主应用的 demo,现在这个主应用是技术栈无关的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那 MicroApp 现在要单独搞个 demo 出来么?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/ui-bindings/react/README.md Outdated Show resolved Hide resolved
packages/ui-bindings/react/README.zh-CN.md Outdated Show resolved Hide resolved
@kuitos
Copy link
Member

kuitos commented Oct 18, 2023

pr 描述记得更新一下 #2706 (comment)

@kuitos kuitos merged commit 1d14f74 into next Oct 19, 2023
@kuitos kuitos deleted the feat/renderer-react branch October 19, 2023 03:42
@kuitos kuitos linked an issue Oct 19, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] 配套的 UI Library(React 版本)
2 participants