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

@leejaehyeok/use-deferred-loading

v0.2.0

Published

A React hook that shows loading state only when loading persists longer than a specified delay, preventing unnecessary UI flicker.

Readme

@leejaehyeok/use-deferred-loading

English | 한국어

A React hook that shows loading state only when loading persists longer than a specified delay, and keeps it visible for a minimum duration. Prevents unnecessary UI flicker from short-lived loading states.

📦 Installation

npm install @leejaehyeok/use-deferred-loading

🚀 Quick Start

The hook takes a loading state and an options object, and returns true only when loading persists longer than the delay.

import React, { useState } from "react";
import { useDeferredLoading } from "@leejaehyeok/use-deferred-loading";

export default function App() {
  const [isLoading, setIsLoading] = useState(false);
  const isDeferredLoading = useDeferredLoading(isLoading, { delay: 300, minDisplayDuration: 500 });

  const handleFetch = async () => {
    setIsLoading(true);
    try {
      await new Promise((resolve) => setTimeout(resolve, 1000));
    } finally {
      setIsLoading(false);
    }
  };

  return (
    <div>
      {isDeferredLoading && <p>Loading...</p>}
      <button onClick={handleFetch} disabled={isLoading}>
        Fetch Data
      </button>
    </div>
  );
}

🧠 Behavior

  • Deferred Loading State: When isLoading becomes true, isDeferredLoading only becomes true after the specified delay (default: 100ms).
  • Flicker Prevention: Short-lived loading states don't trigger UI updates, preventing unnecessary spinner flicker.
  • Minimum Display Duration: Once the spinner appears, it stays visible for at least minDisplayDuration (default: 300ms), preventing an abrupt flash-and-disappear effect.
  • Automatic Cleanup: When isLoading becomes false, isDeferredLoading turns false after the minimum display duration elapses, and all timers are automatically cleared.

⚙️ Parameters

  • isLoading (boolean): Whether the component is currently loading.
  • options (object, optional):
    • delay (number): Delay in milliseconds before showing the loading state. Default is 100ms.
    • minDisplayDuration (number): Minimum time in milliseconds the loading state stays visible once shown. Default is 300ms.

💡 Use Cases

  • Prevent loading UI from showing during quick network requests
  • Improve user experience in search results loading
  • Avoid unnecessary spinner flicker during data fetching

🔗 Links

📄 License

MIT © leejh1316