Reputation: 2157
I have a Blazor server-side project, where I have a custom component that uses a viewmodel to bind to inputbase checkbox.
If I change the viewmodel by clicking on a button, everything works fine. But if I change the viewmodel by something more "background", like a GRPC push message, then the inputbase checkbox is not re-rendered.
Upvotes: 1
Views: 822
Reputation: 2601
As long as the reason for a change is something related to UI, like a click of a button, an input change in a field, etc., in most cases, the render cycle is kicked off by Blazor.
However, if the reason is something more nested like a timer or a finished asynchronous call, you can use the method StateHasChanged
in a component to trigger a new render cycle.
As mentioned in the comment, there might be drawbacks when this method is called outside the UI thread. await InvokeAsync(StateHasChanged)
helps to mitigate the issue. Besides, it is async like nearly which is more Blazor "serverish".
Upvotes: 3