In Svelte 5, using Runes syntax, I'm trying to bind a prop from a child component to the prop of a parent component directly.
The only way I am able to get this to work is by creating a local state variable in the parent and updating the local state value first, before updating the prop with the local state value.
I did not have to do this in Svelte 4 and this seems unnecessarily wordy and clunky.
What am I missing?
Example working binding:
<script>
let { someProp = $bindable() } = $props();
let localPropState = $state(someProp);
$effect(() => {
someProp = localPropState;
});
</script>
<ChildComponent bind:localPropState />
Example not working binding:
<script>
let { someProp = $bindable() } = $props();
</script>
<ChildComponent bind:someProp />
The problem was that further up the component tree someProp was still being set as Svelte 4 $writable instead of Svelte 5 $state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With