useTimeout

Update value after a given time with controls.

Usage

<script>
  import { useTimeout } from '@svelte-use/core'

  const ready = useTimeout(1000)
</script>
<script>
  import { useTimeout, promiseTimeout } from '@svelte-use/core'

  const { ready, start, stop } = useTimeout(1000, { controls: true })

  console.log($ready) // false

  await promiseTimeout(1200)

  console.log($ready) // true
</script>

Type Declarations

export interface TimeoutOptions<Controls extends boolean>
  extends TimeoutFnOptions {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
}
/**
 * Update value after a given time with controls.
 *
 * @see https://svelte-use.vercel.app/core/useTimeout
 * @param interval
 * @param options
 */
export declare function useTimeout(
  interval?: number,
  options?: TimeoutOptions<false>
): Writable<boolean>
export declare function useTimeout(
  interval: number,
  options: TimeoutOptions<true>
): {
  ready: Writable<boolean>
} & Stopable

Source

SourceDemoDocs