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

Svelte child component props doesn't update on parent state change

$
0
0

Parent component:

<script>    import Child from "./Child.svelte"    import { onMount } from "svelte";    import apireq from "./api.js";    let items = $state.raw([]);    let splitItems = $derived(items.splice(0, 5));    onMount(() => {        apireq().then(v => items = v)    })</script><h1>item count in parent {items.length}</h1><Child items={splitItems} />

Child component

<script>  let props = $props();  let { items} = props;</script>item count in child:<div>{items.length}</div>

Child component does not update after the api request.. Still shows 0 countParent does update.

I tried with both $state and $state.raw. But i don't want full reactivity because its a large array, and reactivity on assign should be enough

This used to be so simple in svelte 4, but in 5 nothing works as expected :(


Viewing all articles
Browse latest Browse all 1541

Trending Articles



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