Blazor

What if the component ref/instance is not working? Or the component ref is undefined?

What if the component ref/instance is not working? Or the component ref is undefined?

The component instance filed is populated along with the component after rendering completion. You must access the component instance in the OnAfterRenderAsync or OnAfterRender methods of the Blazor lifecycle.

@page "/"
  
 <Counter IncrementValue="10" @ref="counter"></Counter>
  
 @code {
  
     private Counter counter;    
  
     protected override void OnAfterRender()
     {
         base.OnAfterRender();
         counter.increase(); //access counter instance here
     }
 } 

 

Sumitra Kumari Shaw

An Engineering graduate who Enjoys building things that live on the internet.