ndresx / react-countdown

A customizable countdown component for React.
MIT License
755 stars 70 forks source link

zeroPadTime doesn't look like working #248

Closed rooooonald closed 7 months ago

rooooonald commented 1 year ago

Even I set zeroPadTime={2}, still no zero is padded. ;(

<Countdown date={event.datetime} renderer={renderer} zeroPadTime={2} onComplete={timesUpHandler} />

pedram-taheri commented 10 months ago

{hours ? hours : "00"}:{minutes ? minutes : "00"}:{seconds ? seconds : "00"} use this code in render function to show 00

const renderer = ({ hours, minutes, seconds, completed }) => {
if (completed) {
// Render a completed state
return ;
} else {
// Render a countdown
return {hours ? hours : "00"}:{minutes ? minutes : "00"}:{seconds ? seconds : "00"};
}
};
ndresx commented 7 months ago

Hi, a bit late to this, but in case anyone is running into the same issue.

When using a custom renderer, the formatted output can be found in the formatted object provided to the renderer function.

<Countdown date={Date.now() + 10000} zeroPadTime={2} renderer={({ formatted: { hours, minutes, seconds } }) => {
    return (
      <>
        {hours}:{minutes}:{seconds}
      </>
    );
  }}
/>;