npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-component-async-loader

v1.0.3

Published

The React component asynchronous loader

Downloads

7

Readme

react-component-async-loader

The React component asynchronous loader

REACT组件异步加载器

  • 注意事项:
  1. 异步加载一个组件时,需要判断当前项目中是否该组件都为异步加载,若同一个项目中其他地方有使用该组件,未异步加载。 将致导异步加载失效。
  2. 静默处理异常,加载失败,对应的组件不会出现,不进行消息提醒。
  3. 该方法会在组件挂载时加载资源,如果要做到按需加载,注意组件的挂载时机。

功能

  1. 支持异步加载export default的组件
  2. 支持异步加载export 的react组件

安装

npm i react-component-async-loader

API

asyncComponent

适用于加载export default的React组件

| Arguments | Type | Desc | Required | | --------------- | :------------------------------------------ | --------------------------------- | -------- | | importComponent | () => import(componentName/componentpath) | import 需要加载的组件 | true | | Loading | React Component | 用于异步加载状态展示的loading组件 | false |

asyncMoudleComponent

适用于加载单个export的React组件

| Arguments | Type | Desc | Required | | --------------- | :------------------------------------------ | --------------------------------------- | -------- | | key | string | 通过指定key,加载单个export 的React组件 | true | | importComponent | () => import(componentName/componentpath) | import 需要加载的组件 | true | | Loading | REACT Component, | 用于异步加载状态展示的loading组件 | false |

asyncMoudleComponents

适用于加载多个export的React组件

| Arguments | Type | Desc | Required | | --------------- | :------------------------------------------ | --------------------------------------------- | -------- | | keys | Array[string] | 通过指定keys[key],加载多个export 的React组件 | true | | importComponent | () => import(componentName/componentpath) | import 需要加载的组件 | true | | Loading | REACT Component, | 用于异步加载状态展示的loading组件 | false |

示例

import asyncComponent, { asyncMoudleComponent,asyncMoudleComponents } from "react-component-async-loader";

// 加载npm default组件, 支持传入Loading组件
const CoverTool = asyncComponent(() => import("cover-tool"));

// 加载本地 default组件, 支持传入Loading组件
const Component = asyncComponent(() => import("./component"));

// 加载单个npm module组件, 本地module组件依此类推, 支持传入Loading组件
const ImportTraineeModal = asyncMoudleComponent("ImportTraineeModal", () => import("ice"));

// 同一个组件库加载多个npm module组件, 本地module组件依此类推, 支持传入Loading组件
const { C1, C2 } = asyncMoudleComponents(['C1','C2'], () => import("ice"));