react-usesessiontimer
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

react-useSessionTimer

A hook to get session timer functionality

Installation

npm i react-usesessiontimer or yarn react-usesessiontimer

Usage

import useSessionTimer from "react-usesessiontimer";
 
function App() {
  const { start, stop, reset } = useSessionTimer({
    warnAfter: 3000, // call onWarning callback after 3000ms
    expireAfter: 6000, // call onExpire callback after 6000ms
    onWarning: () => {
      alert("session is about to expire, do something about it ?");
    },
    onReset: () => {
      alert("reset session timer");
    },
    onExpire: () => {
      alert("session expired");
    }
  });
 
  return (
    <button
      onClick={() => {
        start();
      }}
    >
      Start session timer
    </button>
  );
}

Parameters

name type description
warnAfter number ms to wait until it calls the onWarning callback
expireAfter number ms to wait until it calls the onExpire callback
onWarning Fn a function that gets called after warnAfter ms
onExpire Fn a function that gets called after warnAfter ms
onReset Fn a function that gets called when you reset the timer

Returns

name type description
start Fn function to start the timer
stop Fn function to stop the timer
reset Fn function to reset the timer

Todo

  • [] Tests

Readme

Keywords

Package Sidebar

Install

npm i react-usesessiontimer

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

4.42 kB

Total Files

6

Last publish

Collaborators

  • jonathan-san