0.1.6 • Published 4 years ago

react-countdown-hoc v0.1.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

React Countdown HOC

It's a render props component, or FaCC(Function as Child Component).

know more details about render props Render Props – React

Use this Component

yarn add react-countdown-hoc to install the latest version

<Countdown intervalSecond={1} duration={60}>
  {(isCounting, restTime, startCount) => (
    <button disabled={isCounting} onClick={() => startCounting(startCount)}>
      {isCounting ? `${restTime}s` : 'done'}
    </button>
  )}
</Countdown>

Props

NameTypeDefaultDescription
intervalSecondnumberrequiredInterval delay in second
durationnumberrequiredCount down time
childrennumber(isCounting: boolean, durationTime: number, startCount: () => void) => React.ReactNodeA React child for the countdown's state
autoTriggerbooleanundefinedWhen Component mounted, auto starting count
detectChangesstringundefinedA compare condition to rerender countdown

children

You could put a button here but start counting, and display rest of time.

isCounting is a flag to tell you if countdown completed

durationTime tells you rest time for current countdown

startCount is a function, to start count

Contribute to this repo

To install dependencies

$ yarn

To build

$ yarn build

To run tests

$ yarn test

To run Storybook

$ yarn start
0.1.6

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.0.3

4 years ago

0.1.1

4 years ago

0.0.2

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.0.1

4 years ago