Skip to content

Conversation

@Rich-Harris
Copy link
Member

addresses a few points in #16948 (comment)

@changeset-bot
Copy link

changeset-bot bot commented Oct 14, 2025

⚠️ No Changeset found

Latest commit: 00b8948

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@svelte-docs-bot
Copy link

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16952

@7nik
Copy link
Contributor

7nik commented Oct 14, 2025

I guess the context page should be updated as well

@brunnerh
Copy link
Member

brunnerh commented Oct 14, 2025

There would also be the tutorial (different repository, though).

@Rich-Harris
Copy link
Member Author

this is already a bit of a side-quest 😆 I wasn't planning to do any of this yet, I just got nerd-sniped by @stolinski

export function getUserContext() {
return /** @type {User} */ (getContext(key));
}
export const [getUserContext, setUserContext] = createContext<User>();

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too worried about the JSDoc experience tbh. If people care about type safety, and they're building an app rather than a library, they're almost certainly using .ts. And if they don't then they can do the ReturnType thing, it's fine

@Rich-Harris Rich-Harris merged commit d6d13ce into main Oct 15, 2025
18 checks passed
@Rich-Harris Rich-Harris deleted the create-context-docs branch October 15, 2025 00:45
@hyunbinseo
Copy link
Contributor

Is there a reason why createContext is presented as an alternative?

As an alternative to using setContext and getContext directly, you can use them via createContext.

I would love to see it on the top of the Context docs as the default, recommended method.

I know this is a closed issue, but I am not sure if this deserves a new issue. Will create a PR if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants