async-import-react-component
v1.0.1
Published
Support react components import asynchronously, with support for code splitting
Downloads
14
Maintainers
Readme
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.