# @teamix/react-loader

> Load react component with cdn

Latest version **1.0.3** (published 2020-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @teamix/react-loader
pnpm add @teamix/react-loader
yarn add @teamix/react-loader
bun add @teamix/react-loader
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-11-20 |
| First published | 2020-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 799.1 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | purple-force, zaranengap, zuoqi |
| Keywords | teamix, react, component |

## Links

- npm: https://www.npmjs.com/package/@teamix/react-loader
- Homepage: https://unpkg.com/@teamix/react-loader@1.0.3/build/index.html
- npm.io page: https://npm.io/package/@teamix/react-loader

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.21.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.5.8
- [hoist-non-react-statics](https://npm.io/package/hoist-non-react-statics.md) ^3.3.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-11-20
- 1.0.2 — 2020-11-12
- 1.0.2-beta.0 — 2020-11-10
- 1.0.1 — 2020-11-10
- 1.0.0 — 2020-11-10

## README

# reactLoader

@teamix/teamix-react-loader

Load react component with cdn

## 基本用法

````jsx
import TeamixReactLoader from '@teamix/teamix-react-loader';

const loaderOption = {
  dependencies: {},
  fallback: 'loading...',
  error: 'error',
};

const option = {
  js: '',
  css: '',
}

const load = TeamixReactLoader(loaderOption);
const Component = load(option);

// Then you can use Component like normal react Component:
// <Component {...props} />
// ReactDOM.render(<Component />, mountNode);
````

## loaderOption

| 参数名 | 说明 | 必填 | 类型 | 默认值 |
| ------ | ---- | ---- | ---- | ------ |
|    dependencies    |   组件需要的额外依赖   |      |   Dependencies   |    -    |
|    fallback    |  组件加载时显示的元素    |      |   ReactNode   |    -    |   loading...    |
|    error    |  组件加载时错误时显示的元素    |      |   ReactNode   |    -    |   error    |

## option

| 参数名 | 说明 | 必填 | 类型 | 默认值 |
| ------ | ---- | ---- | ---- | ------ |
|    js    |   需要加载的组件js地址   |   ✅   |   String   |    -    |
|    css    |  需要加载的组件css地址    |      |   String   |    -    |       |

## Dependencies
组件内置的依赖如下：
````jsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';

export const DEFAULT_RUNTIME_DEPENDENCIES = {
  react: React,
  'react-dom': ReactDOM,
};
````

loaderOption 参数的 dependencies 也应该如上结构，同时也可以使用 setDefaultDependencies 全局设置。
````jsx
import TeamixReactLoader from '@teamix/teamix-react-loader';
import * as antd from 'antd';
import MyComponent from '@teamix/my-component';

TeamixReactLoader.setDefaultDependencies({
  antd,
  '@teamix/my-component': MyComponent,
});

TeamixReactLoader.setDefaultFallback(<p>Component is loading</p>);

TeamixReactLoader.setDefaultError(<p>Component Error</p>);
````

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