Skip to content
On this page

useNow

Category
Export Size
1.21 kB
Last Changed
last year

Reactive current Date instance.

Demo

Now: Tue Dec 20 2022 13:05:28 GMT+0000 (Coordinated Universal Time)

Usage

js
import { useNow } from '@vueuse/core'

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

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

Component Usage

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

html
<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

typescript
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
sun0day
Shinigami
wheat
Alex Kozack
Antério Vieira

Changelog

No recent changes

Released under the MIT License.