I am trying to alter a flag of a component through its instance but getting an error as The render handle is not yet assigned.
I have a component called PopMessage.razor
@if (isDisplay){<div><span>Message</span></div>}@code{ private bool isDisplay = false; public void PopShow() { try { isDisplay = true; StateHasChanged(); } catch (Exception ex){} }}Registered it as builder.Services.AddScoped<PopMessage>()
And in an another component Home.razor
@page "/"@inject PopMessage _popMessage<button @onclick="PopPrint">Pop message</button><PopMessage/>@code{ private void PopPrint() { _popMessage.PopShow(); }}Now on click of the button it throws the exception message as The render handle is not yet assigned in the PopShow method.
I did not really understand the issue. The component <PopMessage/> is loaded. But on he call of the message PopShow throws this exception. Without StateHasChanged() it does not throw the exception but of course the state does not get updated.