Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Svelte seems to react to assigned variable change

$
0
0

Let’s suppose I have this as main page:

<script>    import Child from "./Child.svelte";    let person = { name: "" };</script><Child {person} />

And this as a child:

<script>    export let person;    let name;    $: name = person.name;</script><input bind:value={name} />

You can try it here.

The reason I don’t directly bind person.name is because I don’t want to mutate parent objects at all, I prefer to throw an event.

I expected to be able to modify the name variable of the child component by typing values in the input. A modification in the parent element However it doesn’t work at all, because the input remains empty whatever I type in it.

After having created this minimal example and put console.log everywhere, it seems that the line $: name = person.name is triggered right after I type something in the input field, while it shouldn’t because person.name doesn’t change, the assigned variable does.

It is surely very easy but I can’t understand why this behaviour happens, so thanks in advance for any help


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>