I have a page with multiple components, like tables and displayed in one page.My +page.svelte:
<script>..<script><div class="page-content"><Row><Table1 /><List /> --><Table2 /></Row></div>
My rest api call as an example in one of my component:
<script>let todos // 'forever' undefined async function fetchTodos() { const response = await fetch('https://jsonplaceholder.typicode.com/todos/') return await response.json() }</script>{#await fetchTodos() then todos}<h1>{todos.length} todos!</h1>{/await}
However if I want to use it inside each tables and some of the data in the List component, according to this solution I need to place the same call all of my component and I generate unnecessary extra same calls.
- What is the proper way to call the endpoint ONCE and reuse the response data in all components?
- I want to poll the rest api call in every 15 seconds and refresh the fields inside the component, so saving extra call would be crucial. Any polling solution?
Any help and example would be appreciated!!