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-import-lazy

v1.0.1

Published

Easy code splitting of React!

Downloads

1

Readme

简体中文 | English

React-import-lazy

react-import-lazy 在 React 内使用,用来异步加载模块并提供降级渲染,一个常用的场景是优化首屏渲染!

👏欢迎 fork 进行学习,交流

提供两种方法,可以根据实际场景各取所需:

  • LazyImport() 基于 React Lazy 来动态渲染组件
  • AsyncImport() 基于 import().then() 方法来动态加载组件

用法

执行 npm install react-import-lazy --save 或者 yarn add react-import-lazy --save 进行安装

这里有一个简单的例子

import React from 'react'
import ReactDOM from 'react-dom'
import { LazyImport, AsyncImport } from 'react-import-lazy'

const Test = AsyncImport({
  action: import('./App'),
  loading: <span>loading</span>
})

// 或者,使用 LazyImport,它们效果是一样的,内部实现方式有所区别,建议使用 AsyncImport
const Test = LazyImport({
  action: import ('./App'),
  loading: <span>loading</span>
})

ReactDOM.render(
  <React.StrictMode>
    {<Test />}
  </React.StrictMode>,
  document.getElementById('root')
)

事实上,我开发这个工具主要用来配合 react-router 使用

Props

| Property | Description | Type | Default | | -------- | -------------- | --------------- | -------------------- | | action | 用来进行包引入 | any | - | | loading | 降级渲染内容 | React.ReactNode | <div>loading</div> |

关于

如果你也想开发一个 npm 包,你可以参考 npm-template 来快速构建属于你的 npm package,欢迎 star and fork👏!

Solo with code✨