Skip to content
On this page

useNow

Category
Last Changed
3 months ago

Reactive current Date instance.

Demo

Now: Sat Mar 05 2022 07:29:39 GMT+0000 (Coordinated Universal Time)

Usage

import { useNow } from '@vueuse/core'

const now = useNow()
import { useNow } from '@vueuse/core'

const now = useNow()
const { now, pause, resume } = useNow({ controls: true })
const { now, pause, resume } = useNow({ controls: true })

Component

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.
<UseNow v-slot="{ now, pause, resume }">
  Now: {{ now }}
  <button @click="pause()">Pause</button>
  <button @click="resume()">Resume</button>
</UseNow>
<UseNow v-slot="{ now, pause, resume }">
  Now: {{ now }}
  <button @click="pause()">Pause</button>
  <button @click="resume()">Resume</button>
</UseNow>

Type Declarations

export interface UseNowOptions<Controls extends boolean> {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
  /**
   * Update interval, or use requestAnimationFrame
   *
   * @default requestAnimationFrame
   */
  interval?: "requestAnimationFrame" | number
}
/**
 * Reactive current Date instance.
 *
 * @see https://vueuse.org/useNow
 * @param options
 */
export declare function useNow(options?: UseNowOptions<false>): Ref<Date>
export declare function useNow(options: UseNowOptions<true>): {
  now: Ref<Date>
} & Pausable
export declare type UseNowReturn = ReturnType<typeof useNow>
export interface UseNowOptions<Controls extends boolean> {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
  /**
   * Update interval, or use requestAnimationFrame
   *
   * @default requestAnimationFrame
   */
  interval?: "requestAnimationFrame" | number
}
/**
 * Reactive current Date instance.
 *
 * @see https://vueuse.org/useNow
 * @param options
 */
export declare function useNow(options?: UseNowOptions<false>): Ref<Date>
export declare function useNow(options: UseNowOptions<true>): {
  now: Ref<Date>
} & Pausable
export declare type UseNowReturn = ReturnType<typeof useNow>

Source

SourceDemoDocs

Contributors

Anthony Fu
Shinigami
wheat
Alex Kozack
Antério Vieira

Changelog

v4.11.2 on 5/30/2021
68c7d - feat(typedef): add return typedefs (#543) (#544)
v5.0.0-beta.2 on 5/25/2021
5bede - feat: introduce components & directives (#486)
v4.9.3 on 5/11/2021
0fff6 - feat!: introduce controls option
v4.3.2 on 3/5/2021
05821 - feat: new function
useNow has loaded