# @qiankunjs/react

> react binding for qiankun

Latest version **0.0.1-rc.14** (published 2024-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @qiankunjs/react
pnpm add @qiankunjs/react
yarn add @qiankunjs/react
bun add @qiankunjs/react
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; popular repo.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.1-rc.14 |
| Published | 2024-01-08 |
| First published | 2023-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 49.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16703 |
| Author | Bravepg |
| Maintainers | kuitos |

## Links

- npm: https://www.npmjs.com/package/@qiankunjs/react
- Repository: https://github.com/umijs/qiankun
- Homepage: https://github.com/umijs/qiankun#readme
- Issues: https://github.com/umijs/qiankun/issues
- npm.io page: https://npm.io/package/@qiankunjs/react

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [@qiankunjs/ui-shared](https://npm.io/package/@qiankunjs/ui-shared.md) ^0.0.1-rc.1

## Recent versions

- 0.0.1-rc.14 (latest) — 2024-01-08
- 0.0.1-rc.15 (rc) — 2026-08-30
- 0.0.1-rc.13 — 2023-12-26
- 0.0.1-rc.12 — 2023-11-21
- 0.0.1-rc.11 — 2023-11-15
- 0.0.1-rc.10 — 2023-11-13
- 0.0.1-rc.9 — 2023-11-13
- 0.0.1-rc.8 — 2023-11-06
- 0.0.1-rc.7 — 2023-10-30
- 0.0.1-rc.6 — 2023-10-24
- 0.0.1-rc.4 — 2023-10-24
- 0.0.1-rc.3 — 2023-10-23
- 0.0.1-rc.2 — 2023-10-23

## README

# qiankun ui binding for react

## Usage

```bash
npm i @qiankunjs/react
```

## MicroApp component

Load (or unload) child apps directly through the `<MicroApp/>` component, which provides loading and error catching-related capabilities:

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

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

When the sub-app loading animation or error capture capability is enabled, the sub-app accepts an additional style class `wrapperClassName`, and the rendered result is as follows:

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

### Load animation

When this capability is enabled, loading animations are automatically displayed when child apps are loading. When the sub-application is mounted and changes to the `MOUNTED` state, the loading status ends and the sub-application content is displayed.

Just pass `autoSetLoading` as a parameter:

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

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

#### Custom loading animation

If you want to override the default loading animation style, you can set a custom loading component `loader` as the loading animation for the child app.

```tsx
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} />} />
  );
}
```

where `loading` is the `boolean` type parameter, `true` indicates that the loading state is still being loaded, and `false` indicates that the loading state has ended.

### Error catching

When this capability is enabled, an error message is automatically displayed when a child app loads unexpectedly. You can pass the `autoCaptureError` property to the sub-app to enable sub-app error capture capabilities:

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

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

#### Custom error capture

If you want to override the default error capture component style, you can set a custom component `errorBoundary` as the error capture component for the child app:

```tsx
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} />}
    />
  );
}
```

### Component Props

| Name | Required | Description | Type | Default |
| --- | --- | --- | --- | --- |
| `name` | yes | The name of the microapp | `string` |
| `entry` | yes | The HTML address of the microapp | `string` |
| `autoSetLoading` | no | Automatically set the loading state of your microapp | `boolean` | `false` |
| `loader` | no | Custom microapps load state components | `(loading) => React.ReactNode` | `undefined` |
| `autoCaptureError` | no | Automatically set up error capture for microapps | `boolean` | `false` |
| `errorBoundary` | no | Custom microapp error capture component | `(error: any) => React.ReactNode` | `undefined` |
| `className` | no | The style class for the microapp | `string` | `undefined` |
| `wrapperClassName` | no | Wrap the microapp loading component, error capture component, and microapp's style classes, and are only valid when the load component or error capture component is enabled | `string` | `undefined` |

## Get the child app load status

The loading status includes: "NOT_LOADED" | "LOADING_SOURCE_CODE" | "NOT_BOOTSTRAPPED" | "BOOTSTRAPPING" | "NOT_MOUNTED" | "MOUNTING" | "MOUNTED" | "UPDATING" | "UNMOUNTING" | "UNLOADING" |

```tsx
import { useRef } from 'react';
import { MicroApp } from '@qiankunjs/react';

export default function Page() {
  const microAppRef = useRef();

  useEffect(() => {
    // Get the child app load status
    console.log(microAppRef.current?.getStatus());
  }, []);

  return <MicroApp name="app1" entry="http://localhost:8000" ref={microAppRef} />;
}
```

---
_Source: https://npm.io/package/@qiankunjs/react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
