2.0.1 • Published 3 years ago

@taglivros/tag-hooks v2.0.1

Weekly downloads
182
License
-
Repository
bitbucket
Last release
3 years ago

TAG Hooks

A Collection of React Hooks created by @taglivros

useCountdown hook

this hook provides a simple countdown with hours, minutes and seconds

Reference

Methods

Method nameArgumentsDescriptionReturns
initializeCountdown()hours?: number; minutes?: number; seconds_?: number endTime?: dateInitializes the countdown with given values. You should use either endDate or hours_ && minutes_ && seconds_ in order to work properlynull
startCountdown()-Starts the countdowninterval (to use with clearInterval())
setTimerError()value: booleanChanges the error state to given valuenull

Properties

PropertyDescription
daysCurrent Countdown Days left
hoursCurrent Countdown Hours left
minutesCurrent Countdown Minutes left
secondsCurrent Countdown Seconds left
hasErrorIndicates state of an error

Usage

import React, { useEffect } from 'react'
import { useCountdown } from '@taglivros/tag-hooks'

const App = () => {
  const {
    initializeCountdown,
    startCountdown,
    days,
    hours,
    minutes,
    seconds } = useCountdown()
  useEffect(() => {
    initializeCountdown({ endDate: new Date(2022, 5, 5, 5) })// insert here a valid date
    startCountdown()
  })

  return (
    <div>
      <h1>{days}</h1>
      <h1>{hours}</h1>
      <h1>{minutes}</h1>
      <h1>{seconds}</h1>
    </div>
  )
}

🚨 Note: You should wrap the component that uses useCountdown with <CountdownProvider> in an higher level due its useContext use:

import React from 'react'
import { CountdownProvider } from '@taglivros/tag-hooks'

const AppWrapper = () => {
  return (
    <CountdownProvider>
      <App />
    </CountdownProvider>
  )
}
2.0.1

3 years ago

2.0.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago