-
Hey everyone - I have an optimization question. I'm trying to fetch an API response at Currently I'm calling the API in api.getSingle('navigation', {}).then((document) => {
// Set `navigation` store
}); Then using that <script lang="ts">
import navigationItems from '$lib/stores/navigation';
</script>
<nav>
{#each navigationItems as item}
<!-- Items in HTML here -->
{/each}
</nav> Right now that only pre-renders <nav>
</nav> And then it fetches the API request client-side during hydration. How do I get the component to be included in the pre-render with the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As suggested by PM on Discord the API call should happen within |
Beta Was this translation helpful? Give feedback.
As suggested by PM on Discord the API call should happen within
load()
for the__layout
file to be included in the pre-rendered files. I've now removed the store altogether, and passed down a prop from__layout
to theHeader
component with the appropriate data.