1.0.1 • Published 5 years ago

react-usesessiontimer v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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

nametypedescription
warnAfternumberms to wait until it calls the onWarning callback
expireAfternumberms to wait until it calls the onExpire callback
onWarningFna function that gets called after warnAfter ms
onExpireFna function that gets called after warnAfter ms
onResetFna function that gets called when you reset the timer

Returns

nametypedescription
startFnfunction to start the timer
stopFnfunction to stop the timer
resetFnfunction to reset the timer

Todo

  • [] Tests