You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To reduce explicit prop drilling in templates and facilitate composability of components using slots, we favor the use of contexts across related components within their respective trees. Though, a challenge arises when considering that svelte contexts are, by nature, non-reactive. We have to pass reactive values as stores, but we want to keep the outer component's props as non-stores (that is, keep the outer component's API as is, where one can bind:value to a simple string).
How should we bind the passed prop value with the component's store-ized value for it to be two way?
To put it in other terms, what we are essentially looking for here is a way to manually hook into any variable's reactivity, regardless of its data-type (primitive or not), with capabilities of get and set methods, without having to declare a reactive statement using the $: syntax.
Opted for simply proxying value to a contextual _value writable using two reactive statements:
exportletvalue: string;const_value=writable(value);
$: value=$_value;
$: _value.set(value)// Do not use "$_value = value" else results in circular dependency
For the time being, this seems like the simplest most straighforward. To revisit if pitfalls are encountered.
Uh oh!
There was an error while loading. Please reload this page.
Task Description
To reduce explicit prop drilling in templates and facilitate composability of components using slots, we favor the use of contexts across related components within their respective trees. Though, a challenge arises when considering that svelte contexts are, by nature, non-reactive. We have to pass reactive values as stores, but we want to keep the outer component's props as non-stores (that is, keep the outer component's API as is, where one can
bind:value
to a simple string).How should we bind the passed prop value with the component's store-ized value for it to be two way?
To put it in other terms, what we are essentially looking for here is a way to manually hook into any variable's reactivity, regardless of its data-type (primitive or not), with capabilities of
get
andset
methods, without having to declare a reactive statement using the$:
syntax.Reading
List of actions
The text was updated successfully, but these errors were encountered: