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

Cannot change object data bound using bind:property. #6507

Closed
pikadun opened this issue Jul 8, 2021 · 1 comment
Closed

Cannot change object data bound using bind:property. #6507

pikadun opened this issue Jul 8, 2021 · 1 comment

Comments

@pikadun
Copy link

pikadun commented Jul 8, 2021

Describe the bug

Cannot change object bound with bind:property when the object is reactivity.

Reproduction

Demo

App.svelte

<script>
	import Test from './Test.svelte'
	export const values = [1,2,3,4]
	$: datas = values.map(value=>({value}))
	$: obj = datas[0]
</script>

<Test bind:obj {datas}/>
<button>{obj.value}</button>

Test.svelte

<script>
	export let datas
	export let obj
	
	const handleClick = (data)=>{
		obj = data
		console.log(obj)
	}
</script>

<div>
	{#each datas as data} 
	   <button on:click={()=>{handleClick(data)}}>{data.value}</button>
	{/each}
</div>
<div>Test.svelte obj value is: {obj.value}</div>

Logs

No response

System Info

https://www.sveltejs.cn/repl/hello-world?version=3.38.3

Severity

blocking all usage of svelte

@tanhauhau
Copy link
Member

Better not bind: a variable that is reactively declared.

See fix: https://svelte.dev/repl/a28ae2f5d22f4ffca7263a15ab5b6f1c?version=3.38.3

closing this in favor of #4933

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

No branches or pull requests

2 participants