getValdresContext
Signature
getValdresContext(): Storevaldres-svelte Read the current store from context
Returns the store set by the nearest setValdresContext / scope ancestor. Most of the time you don't need it — fromState, toStore, and transaction resolve the context store on their own. Reach for it when you need direct store.get / store.set access.
Usage
<script lang="ts">
import { getValdresContext } from "valdres-svelte"
import { countAtom } from "$lib/state"
const store = getValdresContext()
console.log(store.get(countAtom))
</script>
Call during initialization
Svelte throws lifecycle_outside_component for getContext outside component initialization, so capture the store at the top level rather than inside an event handler. To run writes from a handler, use transaction, which captures the store for you.See also
- setValdresContext — provide the store
- transaction — handler-safe transaction runner