Clock razor page
<h1>Current</h1><div id="clock"></div><script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"><script> function updateClock() { var now = moment().format('YYYY-MM-DD HH:mm:ss'); document.getElementById('clock').innerText = now; } updateClock(); setInterval(updateClock, 1000);</script>procram.cs : grobal rendering mode setting for SSR
app.MapRazorComponents<App>() .AddInteractiveServerRenderMode();And installed, moment.js library from Nuget.
But the clock only works after refeshing manually.
I tried
[Inject] private IJSRuntime JSRuntime { get; set; } protected override async Task OnInitializedAsync() { await JSRuntime.InvokeVoidAsync("setInterval"); }or
app.MapRazorComponents<App>() .AddAdditionalAssemblies();But nothing changed.
How can I make it work automatically?