Skip to main content
The SvelteSet class provides a reactive wrapper around JavaScript’s Set. When you add, delete, or clear items, Svelte’s reactivity system is automatically notified.

Import

Usage

Basic usage

Unique selections

Methods

All standard Set methods work and trigger reactivity when they modify the set:
  • add(value) - Adds a value
  • delete(value) - Removes a value
  • clear() - Removes all values
  • has(value) - Checks if value exists (doesn’t trigger reactivity)
  • size - Property that returns the number of elements

Notes

  • More efficient than using $state() with a regular Set
  • Iteration methods work as expected (forEach, keys, values, entries)
  • The Set is proxied to track changes automatically

See also