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

use-idle-redirect

v1.0.0

Published

React hooks for inactivity timeouts: warn before session expiry with a live countdown, then log out / redirect. Synced across browser tabs, throttled, SSR-safe. Bank-style auto logout in a few lines.

Readme

use-idle-redirect

npm size

Bank-style auto logout for React. Warn the user before their session expires with a live countdown, then log out and redirect — synced across all open tabs.

import { useIdleRedirect } from 'use-idle-redirect';

export function SessionGuard() {
  const { isWarning, remaining, reset } = useIdleRedirect({
    timeout: 15 * 60_000,      // 15 minutes of inactivity
    warningBefore: 60_000,     // warn during the last minute
    onIdle: () => fetch('/api/logout', { method: 'POST' }),
    redirectTo: '/login',      // → /login?reason=idle&returnTo=/current/page
  });

  if (!isWarning) return null;
  return (
    <div role="alertdialog" aria-live="assertive">
      You will be signed out in {Math.ceil(remaining / 1000)} seconds.
      <button onClick={reset}>Stay signed in</button>
    </div>
  );
}

Put <SessionGuard /> once in your authenticated layout.

Install

npm install use-idle-redirect

Features

  • Warning stage with a live remaining countdown (updates every second only while warning).
  • Cross-tab: activity in any tab keeps all tabs signed in (BroadcastChannel + localStorage fallback).
  • Correct in background tabs: status is computed from timestamps, so throttled timers don't cause late or early logouts.
  • Throttled listeners (mousemove, keydown, scroll, touchstart, …) — negligible overhead.
  • Once idle, stray mouse moves don't "wake" the session; only reset() does.
  • SSR-safe.

API

useIdleRedirect(options)

All useIdleTimer options plus:

| Option | Default | Description | | --- | --- | --- | | redirectTo | '/login' | Target URL | | withReturnTo | true | Adds ?reason=idle&returnTo=<path> | | onIdle | – | Async logout logic, awaited before redirect | | navigate | location.assign | Custom navigation, e.g. React Router navigate or Next router.replace |

useIdleTimer(options) — just the timer

| Option | Default | Description | | --- | --- | --- | | timeout | 900000 (15 min) | Inactivity until idle | | warningBefore | 60000 | Warning stage length (0 = none) | | onWarn(remaining), onIdle(), onActive() | – | Transition callbacks | | events | mouse/keyboard/touch/scroll | Activity events | | crossTab | true | Sync between tabs | | storageKey | 'idle-timer' | Sync channel name | | throttle | 500 | Listener throttle, ms | | enabled | true | Disable (e.g. on public pages) |

Returns { status: 'active' | 'warning' | 'idle', isIdle, isWarning, remaining, lastActive, reset(), pause(), resume() }.

Next.js / React Router

const router = useRouter(); // next/navigation
useIdleRedirect({ timeout: 10 * 60_000, navigate: (url) => router.replace(url), onIdle: signOut });

License

MIT