Skip to content

Headless Mode & Multi-Instance

useToastState — headless mode

Returns raw reactive data from the queue. Use it to build a completely custom notification UI — <ToastContainer> is not needed.

ts
const { active, pending, count, has } = useToastState(context?: ToastContext)

Return value

PropertyTypeDescription
activeComputedRef<ToastItem[]>Currently visible toasts (excluding hidden grouped ones)
pendingComputedRef<ToastItem[]>Toasts waiting for a slot
countComputedRef<number>active.value.length
has(id)(id: string) → booleanCheck if a toast is active

Example — fully custom render

vue
<script setup lang="ts">
import { useToast, useToastState } from 'vue-toast-kit'

const toast = useToast()
const { active } = useToastState()
</script>

<template>
  <!-- No <ToastContainer> — render entirely from scratch -->
  <div class="my-notifications">
    <div
      v-for="t in active"
      :key="t.id"
      :class="`notification notification--${t.options.type}`"
      @mouseenter="t.pause()"
      @mouseleave="t.resume()"
    >
      <span>{{ t.message }}</span>
      <button @click="t.dismiss()">✕</button>
      <div class="progress" :style="{ width: `${t.remaining.value * 100}%` }" />
    </div>
  </div>
</template>

Each ToastItem in active is fully reactive:

Property / MethodTypeDescription
idstringUnique id
messagestring | VNodeToast content
optionsToastOptions (required)Merged options
createdAtnumberDate.now() at creation
remainingRef<number>0–1, fraction of timer remaining
isPausedRef<boolean>Timer is paused
groupCountRef<number>1 normally; >1 when grouping is active
pause()() → voidPause the timer
resume()() → voidResume the timer
dismiss()() → voidClose the toast
update(opts)(Partial<ToastOptions>) → voidMerge new options

createToastContext — multi-instance

Creates an isolated queue instance. Pass it to useToast(ctx) and <ToastContainer :context="ctx" /> to completely separate the notification scope from the global one.

ts
const ctx = createToastContext(options?: GlobalToastOptions): ToastContext

Use cases:

  • Micro-frontend shells where each MFE manages its own notifications
  • Modal dialogs with local status toasts that must not interfere with the app-level queue
  • Multiple separate notification zones on one page

Example

vue
<script setup lang="ts">
import { createToastContext, useToast, ToastContainer } from 'vue-toast-kit'

const modalCtx = createToastContext({ maxVisible: 3 })
const modalToast = useToast(modalCtx)

function save() {
  modalToast.success('Changes saved inside the modal')
}
</script>

<template>
  <div class="modal">
    <button @click="save">Save</button>

    <!-- This container only shows toasts from modalCtx -->
    <ToastContainer :context="modalCtx" position="top-right" :z-index="10001" />
  </div>
</template>