Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh current page in SvelteKit

Is there any way to refresh page in every 10 seconds using SvelteKit? I have to refresh page to get output from endpoint.

Loading data in src/routes/[id].svelte from src/routes/[id].ts.

like image 588
Tempus Avatar asked Oct 23 '25 11:10

Tempus


1 Answers

To refresh an endpoint you can use invalidate in your page route.

import { onDestroy } from "svelte";
import { invalidate } from "$app/navigation";

export your_end_point_prop;

// resfresh your_end_point_prop
const apiInterval = setInterval(async () => {
  await invalidate("/your_endpoint");
}, 1000000); 

... code to handle your end_point_prop

onDestroy(() => {
    clearInterval(apiInterval);
});
like image 182
voscausa Avatar answered Oct 25 '25 05:10

voscausa