Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Is the NET 8 Blazor web app template flawed?

$
0
0

Is the template project which gets data for the weather page flawed in the sense that data is retrieved in the OnInitializedAsync() method?

  • In the real world, you likely want pre-rendering to occur
  • You want some sort of "loading..." indicator while you obtain your data
  • And assume getting the data is a "long running" process

The template project will get the data twice, if you refresh the weather page (or request it directly from the browser), rather than using the interactive (enhanced) navigation from another page.

It seems a much better way to handle this situation is to do something like the following (I am using a weatherService to get the WeatherForecast data):

protected override async Task OnAfterRenderAsync(bool firstRender){    if (firstRender)    {        forecasts = await weatherService.GetWeather();        StateHasChanged();    }    await base.OnAfterRenderAsync(firstRender);}

This seems to be the simplest way to guarantee that the app is not accessing the data twice.

Am I missing something?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>