Skip to main content
The SvelteMap class provides a reactive wrapper around JavaScript’s Map. When you set, delete, or clear entries, Svelte’s reactivity system is automatically notified.

Import

Usage

Basic usage

Cache with reactive updates

Form data management

Methods

All standard Map methods work and trigger reactivity when they modify the map:
  • set(key, value) - Sets a key-value pair
  • delete(key) - Removes an entry
  • clear() - Removes all entries
  • get(key) - Gets a value (doesn’t trigger reactivity)
  • has(key) - Checks if key exists (doesn’t trigger reactivity)
  • size - Property that returns the number of entries

Notes

  • More efficient than using $state() with a regular Map
  • Iteration methods work as expected (forEach, keys, values, entries)
  • The Map is proxied to track changes automatically
  • Useful for key-value data that needs to be reactive

See also