Is there a way to bind object field in Svelte 3?
Example:
<script>
import MyComponent from "./MyComponent.svelte"
let myobjectID
</script>
<MyComponent bind:myobject[id]={myobjectID}>
<!-- Where myobject == {id: "123", name: "myName", and so on...} -->
Is this possible?
No there isn't.
If you want
MyComponent
to work internally with an object, but only allow the consumer to change a specific part of that object you could do as follows:App.svelte
MyComponent.svelte
But a more generic way where you would be able to do this way any property of
myobject
does not exist, in that case you're better off not using an object internally for your component and just constructing it as an object when you need it.