-
in this case, There are two variables here that are not responsive。the one is “name”, the other is “data = { name: '***'}”,The code is as follows: I want to know that neither variable is responsive, why is one wrapped in effect and the other outside effect? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Even with analysis, it is virtually impossible to capture all cases, e.g. someone could make the object stateful later by using <script>
let name = $state('tama');
const data = { name: '...' };
Object.defineProperty(data, 'name', {
get() { return name; }
});
</script>
<input bind:value={name} />
<p>{data.name}</p> |
Beta Was this translation helpful? Give feedback.
name
, being a single value, can never be reactive if not declared with$state
.data.name
is a property access which makes this a bit more complicated. Svelte could potentially analyze that this particular object is not stateful, but ifdata
were to e.g. be imported from another module, it might be stateful.Even with analysis, it is virtually impossible to capture all cases, e.g. someone could make the object stateful later by using
Object.defineProperty
and making a property reference live state via aget
function.