Skip to main content
Get the current value from a store by subscribing and immediately unsubscribing. This is useful when you need to read a store value outside of the reactive context.

Usage

Signature

store
Readable<T>
A readable or writable store to get the value from.
T
any
The current value of the store.

When to use get()

Use get() when you need to read a store value outside of Svelte’s reactive context:
  • In event handlers where you need the current value but don’t want to reactively track it
  • In regular JavaScript/TypeScript modules (not components)
  • When you need a one-time snapshot of the value
  • In server-side code or utility functions
Note: Inside Svelte components, prefer using the $ prefix for auto-subscription, which keeps your component reactive:

Examples

In event handlers

In utility functions

Conditional logic

Derived stores with get()

Server-side usage

Comparing values

Avoid overuse

While get() is useful, avoid overusing it in Svelte components. The $ prefix provides automatic subscription management:

TypeScript