From a63bf862c03d5c63b73e412f2ca952cb83d444d8 Mon Sep 17 00:00:00 2001 From: Mukunda Rao Katta Date: Mon, 18 May 2026 12:42:20 -0700 Subject: [PATCH] docs: clarify context state getter pattern (#18226) Closes #18022 This updates the context docs to show the getter pattern for state that may be reassigned, such as primitive state. The new example passes a function through context so children read the current value instead of capturing the initial value. This is a docs-only clarification and does not change runtime behavior. Validation: - `git diff --check` - `pnpm exec prettier --check documentation/docs/06-runtime/02-context.md` Full `pnpm test`/`pnpm lint` were not run because this only changes documentation. --------- Co-authored-by: Rich Harris --- documentation/docs/06-runtime/02-context.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/docs/06-runtime/02-context.md b/documentation/docs/06-runtime/02-context.md index aee51c9a78..439272df8f 100644 --- a/documentation/docs/06-runtime/02-context.md +++ b/documentation/docs/06-runtime/02-context.md @@ -163,6 +163,8 @@ export const [getCounter, setCounter] = createContext(); Svelte will warn you if you get it wrong. +Similarly, to pass primitive values through context, use functions as described in [Passing state into functions]($state#Passing-state-into-functions). + ## Component testing When writing [component tests](testing#Unit-and-component-tests-with-Vitest-Component-testing), it can be useful to create a wrapper component that sets the context in order to check the behaviour of a component that uses it. As of version 5.49, you can do this sort of thing: