amrlabib / react-timer-hook

React timer hook

Home Page:https://www.npmjs.com/package/react-timer-hook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to dynamically change offsetTimestamp in useStopwatch

veeramarni opened this issue · comments

I want to change the offsetTimestamp dynamically to start from speicied value, but once the useStopwatch initialize, it doesn't take updated offsetTimestamp


export default function App() {
  const stopwatchOffset = new Date(); 
  const nn = stopwatchOffset.setSeconds(stopwatchOffset.getSeconds() + 300);
  const [timeDuration, setTimeDuration] = useState<number>(nn);
  return (
    <HeaderTimerHandler timeDuration={timeDuration} setTimeDuration={setTimeDuration} />
  );
}


const HeaderTimerHandler: React.FC<HeaderTimerHandlerProps> = (props) => {
  const { start, hours, minutes, seconds } = useStopwatch({ autoStart: false, offsetTimestamp: props.timeDuration });
  const hidePopover = () => {
    setVisiblity(false);
  }
 return <>{hours:minutes:seconds}</>

I figured out, i can use reset(<offsettime>) instead of start()