react-compound-timer
react-compound-timer copied to clipboard
how to get current time
Hi, thanks for this awesome plugin, but i just couldn't figure out that how can i get current time on a click of a custom button.
I would also like to know how to do this?
Hi, you can create a ref for the timer and then use getTime()
like this:
timerRef.current.getTime()
hope that helps!
In typescript I get the following error -
Property 'getTime' is private and only accessible within class 'Timer'.ts(2341)
I've updated the private
to public
in Timer.d.ts
and now there is no TS error, and they work.
@volkov97 @yannbf @JefferyHus Can you make Timer.tsx
common functions, like getTime, setTime, start, stop, pause, etc...
(all the ones listed in my screenshot above) public
rather then private
functions? This will help build the correct Timer.d.ts
anywhere I install this package. Currently typescript throws errors when I try to access them from the Timer.current
ref.
P.S. I'm somewhat new to typescript ecosystem, how come when I yarn add
this package it correctly creates the build
folder, but after I made a fork and yarn add
the fork repository, there is no build
folder?
Update: Seems like the useTimer() hook doesn't have this typescript issue.
Would it be too much to ask to pass the current time in the onStop(), onPause(), and onReset() events? It would be so much easier than using a consumer or ref.