项目作者: vortesnail

项目描述 :
? Allows you to load React components asynchronously from split chunks / 允许你异步地加载分割出的 React 组件
高级语言: TypeScript
项目地址: git://github.com/vortesnail/async-import-react-component.git
创建时间: 2020-08-12T06:51:13Z
项目社区:https://github.com/vortesnail/async-import-react-component

开源协议:MIT License

下载



Async Import React Component

Async Import React Component


Allows you to load React components asynchronously!





Build And Test


Tests Passing




简体中文
·
English


What it is?

This is a simple Higher-order function that allows you to load React components asynchronously from split chunks.

How to use?

Install

  1. npm install async-import-react-component --save

Usage

You can use two methods, one is to pass in the function directly, and the other is to pass in as an object.

  • Directly
  1. import getAsyncComponent from 'async-import-react-component'
  2. const ComponentOne = getAsyncComponent(() => import('Components/ComponentOne'))
  • Optically
  1. import getAsyncComponent from 'async-import-react-component'
  2. const ComponentTwo = getAsyncComponent({
  3. resolve: () => import('Components/ComponentTwo'),
  4. loading: <div>ComponentTwo is loading...</div>,
  5. error: <div>An error has occurred, please check the component you import.</div>,
  6. delay: 1000,
  7. })

Options

parameters description type default
resolve function importing component path Promise<{ default: ComponentType }> -
loading prompt when loading ReactNode null
error prompt when error ReactNode null
delay Set a delay to start importing number 0

Need help!

In view of the lack of self writing test ability, please have the ability to write unit test friend can contribute to improve this simple project, I will be very grateful to you.