async-import-react-component
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

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
import getAsyncComponent from 'async-import-react-component'
 
const ComponentOne = getAsyncComponent(() => import('Components/ComponentOne'))
  • Optically
import getAsyncComponent from 'async-import-react-component'
 
const ComponentTwo = getAsyncComponent({
  resolve: () => import('Components/ComponentTwo'),
  loading: <div>ComponentTwo is loading...</div>,
  error: <div>An error has occurred, please check the component you import.</div>,
  delay: 1000,
})

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.

Package Sidebar

Install

npm i async-import-react-component

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

14 kB

Total Files

6

Last publish

Collaborators

  • vortesnail