Documentation
Base
Contexts
TimerContext

useTimerContext

Description

The useTimerContext hook is a React hook designed to manage an internal timer. This timer can be used to handle expiration times for various components within your application. It provides a range of functionalities such as starting, pausing, stopping, and resetting the timer. The hook also allows you to change the expiration time and manage the manual state of the timer.

Properties

PropertyTypeDescription
activebooleanIndicates whether the timer is active.
manuallybooleanIndicates whether the timer is in manual state.
expiredbooleanIndicates whether the timer has expired.
durationnumberThe expiration time in milliseconds.
timenumberThe current time value.
stopFunctionStops the timer and resets the time to 0.
pauseFunctionPauses the timer.
startFunctionStarts the timer.
resetFunctionResets the timer by stopping and then starting it again.
change(expires: number, counter?: number) => voidChanges the expiration time of the timer.
setManually(manually: boolean) => voidChanges the manual state of the timer.
setWaiting(waiting: boolean) => voidChanges the waiting state of the timer.

Usage

import { useTimerContext } from "@react-instastories/base";
 
function useTimerStringify() {
  const timer = useTimerContext();
 
  return JSON.stringify(timer);
}

Demo