Skip to content

🌲 Allows you to load React components asynchronously from split chunks / 允许你异步地加载分割出的 React 组件

License

Notifications You must be signed in to change notification settings

vortesnail/async-import-react-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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,
})

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.

About

🌲 Allows you to load React components asynchronously from split chunks / 允许你异步地加载分割出的 React 组件

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published