1.0.3 • Published 3 years ago

@teamix/react-loader v1.0.3

Weekly downloads
7
License
MIT
Repository
-
Last release
3 years ago

reactLoader

@teamix/teamix-react-loader

Load react component with cdn

基本用法

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

组件内置的依赖如下:

import * as React from 'react';
import * as ReactDOM from 'react-dom';

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

loaderOption 参数的 dependencies 也应该如上结构,同时也可以使用 setDefaultDependencies 全局设置。

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>);