Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to combine bindable state prop + context #15222

Open
leekeh opened this issue Feb 5, 2025 · 2 comments
Open

How to combine bindable state prop + context #15222

leekeh opened this issue Feb 5, 2025 · 2 comments

Comments

@leekeh
Copy link

leekeh commented Feb 5, 2025

Describe the problem

I'm looking for a way to use context with a bindable prop state. The documentation describes how you need to pass a $state object to the context in order for it to be reactive. However, I would like to use a $state that is coming in as a bindable property, this does not seem to work.

Here is a REPL of the situation: https://svelte.dev/playground/86a850f39b684dbf8541d595d1f60257?version=5.19.7

Image

Describe the proposed solution

If possible, I would like bindable states to be reactive out of the box. Alternatively, it would be nice to have some documentation on how to implement this pattern.

Importance

would make my life easier

@leekeh leekeh changed the title How to combine How to combine bindable state prop + context Feb 5, 2025
@Ocean-OS
Copy link
Contributor

Ocean-OS commented Feb 5, 2025

Context isn't inherently reactive; to use reactive primitives in context, you'd have to wrap it with a callback or accessor property. You could try something like this.

@leekeh
Copy link
Author

leekeh commented Feb 11, 2025

Context isn't inherently reactive; to use reactive primitives in context, you'd have to wrap it with a callback or accessor property. You could try something like this.

Thanks, that did work for my specific issue. It would be nice to have a bit more info on this behavior and why it works this way in the documentation.

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

No branches or pull requests

3 participants