I have a small thing that I need to do. There's my problem. I open a component, and then I can click "edit" and then I need 3-4 seconds while that need html/css is shown on the page. What I'm trying to do is that when I click "edit" I set "loading = true", and when component finishes rendering that new html/css I set "loading = false". Here is a sample of what I'm trying to achieve:
if (!edit) {
<h2>test</h2>
@foreach (var item in items) {
<p>Test item</p>
}
}
else {
<button @onclick = "() => { edit = true; }">
<h2>test other </h2>
<input />
<input />
}
This is how I set loading spinner to show on page:
await InvokeAsync(() => { loading = true; });
await InvokeAsync(() => { loading = false; });
So, my question is how can I make that when a person presses edit, the spinner automatically starts spinning on the screen. I know how to do it when OnInitializedAsync, but at this specific situation, it's not being initialized, it just shows a different part of the component (but it takes 5 seconds, huge code). Is there a way?
Thread.Sleep(1)to yield for the screen to update after each time you set the loading flag. - Brian Parker