I have a function in a +page.js file that return { props { data } }. Data is an array. However when I try to use it in svelte with
export let data
It says that it's not an array What should I do ?
I have a function in a +page.js file that return { props { data } }. Data is an array. However when I try to use it in svelte with
export let data
It says that it's not an array What should I do ?
You need to ensure the array is properly imported and managed in the Svelte component. Confirm the data is indeed an array (use console.log(data)
). If it expected values or undefined, double-check that:
If data is fetched asynchronously and might not be immediately available, use the await
keyword in your load function.
If everything looks good then you access the data correctly. FYR:
<!-- +page.svelte -->
<script>
export let data;
// Verify if data is received correctly
console.log(data);
</script>
{#if Array.isArray(data)}
<ul>
{#each data as item}
<li>{item}</li>
{/each}
</ul>
{:else}
<p>Data is not an array or not loaded correctly.</p>
{/if}