how to dynamically change offsetTimestamp in useStopwatch
veeramarni opened this issue · comments
veeramarni commented
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}</>
veeramarni commented
I figured out, i can use reset(<offsettime>)
instead of start()