Skip to content

useCountDown

Used for handling countdown-related logic.

Basic Usage

ts
import { useCountDown } from '@/uni_modules/wot-design-uni'

const { start, pause, reset, current } = useCountDown({
  time: 60 * 1000,
  onChange(current) {
    console.log('Remaining time', current)
  },
  onFinish() {
    console.log('Countdown finished')
  }
})

// Start countdown
start()

// Pause countdown
pause()

// Reset countdown
reset()

// Get current time
console.log(current.value)

API

Parameters

ParameterDescriptionTypeDefault
timeTotal countdown time (ms)number-
millisecondWhether to enable millisecond-level renderingbooleanfalse
onChangeCountdown change callback(current: CurrentTime) => void-
onFinishCountdown finish callback() => void-

Methods

Method NameDescriptionParametersReturn Value
startStart countdown--
pausePause countdown--
resetReset countdowntime?: number-

CurrentTime Structure

ts
type CurrentTime = {
  days: number
  hours: number
  total: number
  minutes: number
  seconds: number
  milliseconds: number
}

Released under the MIT License.

Released under the MIT License.