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

react-session-timer

v1.0.4

Published

A lightweight React library for handling user inactivity, session timeouts, and warning popups with customizable hooks and components.

Readme

react-session-timer

A React session timer package that tracks user session time, shows a warning modal before expiration, and provides hooks to extend or reset sessions. Perfect for apps that require auto-logout functionality.

⏰ Easy session management with one hook — start, extend, reset, and stop sessions programmatically.

Features

  • Countdown session timer with customizable duration
  • Warning modal before session expires
  • Easy-to-use hook and context for global session state
  • Extend, reset, and stop session programmatically
  • Fully typed with TypeScript

Installation

npm install react-session-timer
# or
yarn add react-session-timer

Usage

    1. Wrap your app with SessionTimerProvider
import React from "react";
import { SessionTimerProvider } from "react-session-timer";
import App from "./App";

const Root = () => (
  <SessionTimerProvider
    duration={300} // session duration in seconds (5 minutes)
    warningThreshold={60} // show warning when 60 seconds left
    onTimeout={() => alert("Session expired")}
    onWarning={() => console.log("Warning: session about to expire")}
  >
    <App />
  </SessionTimerProvider>
);

export default Root;
    1. Use the hook to access session state
import React from "react";
import { useSessionTimer } from "react-session-timer";
import WarningModal from "react-session-timer/dist/components/WarningModal";

const Dashboard = () => {
  const { remainingTime, isWarningVisible, extend, stop } = useSessionTimer();

  const handleExtend = () => extend(120); // add 2 more minutes
  const handleLogout = () => stop(); // stop session (could redirect to login)

  return (
    <div>
      <h1>Dashboard</h1>
      <p>Time remaining: {remainingTime} seconds</p>
      <WarningModal
        remainingTime={remainingTime}
        visible={isWarningVisible}
        onExtend={handleExtend}
        onLogout={handleLogout}
      />
    </div>
  );
};

export default Dashboard;

API

SessionTimerProvider props

| Prop | Type | Default | Description | | ------------------ | ------------ | ------- | ----------------------------------------------------------------- | | duration | number | — | Total session time in seconds (e.g. 300 for 5 minutes). | | warningThreshold | number | 60 | Time (in seconds) before expiration to trigger the warning modal. | | onTimeout | () => void | — | Callback fired when the session expires. | | onWarning | () => void | — | Callback fired when the warning threshold is reached. | | children | ReactNode | — | The app or components wrapped by the provider. |

Hook: useSessionTimer()

Returns:

{
  remainingTime: number;
  isWarningVisible: boolean;
  start: () => void;
  reset: () => void;
  extend: (extraSeconds?: number) => void;
  stop: () => void;
}

Component: WarningModal

Props:

  • remainingTime: number – seconds left
  • visible: boolean – show/hide modal
  • onExtend: () => void – extend session
  • onLogout: () => void – logout or stop session

Notes

  • You can rotate or extend the session duration dynamically using extend().
  • Works with React 18+ and TypeScript.
  • Compatible with browser environments only.