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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@figliolia/react-lazy

v3.0.1

Published

Lazy loadable components powered by the Scheduler API

Readme

React Lazy

Lazy loadable components powered by the Scheduler API.

Installation

npm i -S @figliolia/react-lazy

Basic Usage

import type { ErrorInfo } from "react";
import { CreateLazyComponent } from "@figliolia/react-lazy";

const MyLazyComponent = CreateLazyComponent({
  fallback: <div>Loading</div>,
  errorBoundary: <div>Whoops!</div>,
  loader: () => import("./path/to/Component"),
  onError: (error: Error, errorInfo: ErrorInfo) => {},
  delay: undefined, // optional millisecond delay
  priority: "user-visible", // user-blocking, user-visible, or background;
  signal: undefined, // an optional abort signal to bail out of the loader
});

// Optionally Preload your component using:
void MyLazyComponent.preload()

// Render your component without preloading and it'll
// load on mount
export const MyApp () => {
  return (
    <main>
      <MyLazyComponent {...lazyComponentProps} />
      {/* your other component markup */}
    </main>
  );
}

CreateLazyComponent()

Parameters

loader: An async function that resolves to { default: ComponentType<T> }. This function is passed to React.lazy().

fallback: (optional) A ReactNode to display while to the lazy component is suspended

errorBoundary: (optional) A ReactNode to display if the lazy component throws an error. Utilizing this option will cause your lazy loaded component to be wrapped in it's own ErrorBoundary

onError: (optional) A callback to execute if the lazy component throws an error. Utilizing this option will cause your lazy loaded component to be wrapped in it's own ErrorBoundary

priority: (optional) A valid TaskPriority - user-blocking, user-visible, or background. The execution order of loadable components will correspond to the above order. When undefined, loading tasks will default to user-visible

signal: (optional) An abort signal to bail out of loading tasks

delay: (optional) A millisecond delay with which to schedule your loader

Returns

A LazyComponent instance

Advanced Usage - Preloading

This feature is an additional optimization that allows you to optimistically load dynamic components ahead of when they're actually needed.

Consider a case where you have a user logging into your application for the first time. When they press your login button, you'll probably send a request to your server to validate the user's credentials - then, if they are valid, you'll redirect the user into your app.

While the credentials are being sent to the server, it may also be prudent to securely preload some of the components that are sitting behind your authentication. A working example may look something like the following:

import { useRef, useCallback } from "react";
import { LazyHeader, LazyContent, LazyFooter } from "./your-app-components";

export const LoginScreen = () => {
  const preloaded = useRef(false);

  const preloadComponents = useCallback(async () => {
    if(preloaded.current) {
      return;
    }
    try {
      await Promise.all([
        LazyHeader.preload(),
        LazyContent.preload(),
        LazyFooter.preload(),
      ]);
      preloaded.current = true;
    } catch() {
      // silence
    }
  }, [preloaded])

  const onSubmit = useCallback(async (e) => {
    e.preventDefault();
    void preloadComponents();
    try {
      await fetch("/api/auth", {
        method: "POST",
        body: JSON.stringify(/* Login Credentials */)
      });
      redirect("to/your/app");
    } catch(e) {
      // handle error
    }
  }, [preloadComponents]);

  return (
    <form onSubmit={onSubmit}>
      {/* login inputs */}
      <button type="submit" value="Login" />
    </form>
  );
}

Using this technique, we can utilize the time that an API request is already in-flight to cache component JavaScript & CSS in the browser. This way when authentication completes the redirect to our main application content is instantaneous.