react-compound-timer icon indicating copy to clipboard operation
react-compound-timer copied to clipboard

how to get current time

Open PradhumnSingh opened this issue 4 years ago • 7 comments

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.

PradhumnSingh avatar Apr 09 '20 16:04 PradhumnSingh

I would also like to know how to do this?

KmBarnett avatar Apr 17 '20 16:04 KmBarnett

Hi, you can create a ref for the timer and then use getTime() like this: timerRef.current.getTime()

hope that helps!

malinantonsson avatar May 15 '20 20:05 malinantonsson

In typescript I get the following error -

Property 'getTime' is private and only accessible within class 'Timer'.ts(2341)

uadarsh avatar Jun 10 '20 14:06 uadarsh

I've updated the private to public in Timer.d.ts and now there is no TS error, and they work.

image

ariel-frischer avatar Aug 27 '20 07:08 ariel-frischer

@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?

ariel-frischer avatar Aug 27 '20 08:08 ariel-frischer

Update: Seems like the useTimer() hook doesn't have this typescript issue.

ariel-frischer avatar Aug 27 '20 18:08 ariel-frischer

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.

ysageev avatar Apr 12 '21 16:04 ysageev