react-countdown-clock icon indicating copy to clipboard operation
react-countdown-clock copied to clipboard

When use 2 countdowns, when first finished, it stops the second too.

Open yan87 opened this issue 7 years ago • 10 comments

Hi,

I am new with React, I try use 2 countdown clocks, the problem when the first finished (onComplete), the second one stops. How can I run multiple react-countdown-clock?

yan87 avatar Nov 10 '17 15:11 yan87

Sorry for the delayed response. If this is still a problem, please post an example and I will take a look.

pughpugh avatar Dec 21 '17 19:12 pughpugh

@pughpugh This is still an issue.

zchauhan avatar Dec 26 '17 10:12 zchauhan

OK thanks @zchauhan , I will take a look.

pughpugh avatar Dec 26 '17 11:12 pughpugh

@pughpugh

The issue is with below code

_stopTimer: ->
    for timeout in @_timeoutIds
      clearTimeout timeout

zchauhan avatar Dec 26 '17 11:12 zchauhan

Yup. Timeout IDs need to be stored in state, not on the component definition. They are currently bleeding across instances. I think this is the cause of a number of problems at the moment.

pughpugh avatar Dec 26 '17 11:12 pughpugh

Yes, You are right. I am wondering how props can be shared ? May be due to passByRefference nature for object/array in javascript ?

zchauhan avatar Dec 26 '17 11:12 zchauhan

Any update on this?

dannykoshy avatar Apr 03 '18 09:04 dannykoshy

Bump! Any news or workaround?

Simek avatar Jun 11 '18 09:06 Simek

Hey thanks,

I had solved it. Cheers!

On Mon, Jun 11, 2018 at 5:12 PM Bartosz Kaszubowski < [email protected]> wrote:

I've manage to implement little, dirty w/o in which I've override start/stop methods and lift timeoutIds to component wrapper state:

export default class Counter extends ReactCountdownClock { constructor(props) { super(props); this.state = { tids: [] };

  this._stopTimer = () => {
  	for (let timeout in this.state.tids) {
  		clearTimeout(timeout);
  	}
  };

  this._startTimer = () => {
  	this.setState({ tids: setTimeout(this._tick(), 200)});
  };

} }

It's not pretty or solid code but works.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pughpugh/react-countdown-clock/issues/41#issuecomment-396193176, or mute the thread https://github.com/notifications/unsubscribe-auth/AXaLR7-DWw4sbrNMMsNdRHzunsd4rjEaks5t7kKBgaJpZM4QZvox .

dannykoshy avatar Nov 01 '18 19:11 dannykoshy

Hi all,

also bumped into this... It's really a blocker, is the fix planned?

Thanks a lot.

obrejla avatar Oct 08 '19 11:10 obrejla