Blazor

How do I get the reference or instance of a component?

How do I get the reference or instance of a component?

Component references are used to invoke methods from underlying components. Use the ref attribute for a component and define it filed with the same name and same type of component.

 @page "/"
  
 <Counter IncrementValue="10" @ref="counter"></Counter>
  
 @code {
  
     private Counter counter;    
  
 } 

While the Counter component is rendered, the field counter is populated along with the component instance.

I would suggest you check the below link for better understanding:

https://docs.microsoft.com/en-in/aspnet/core/blazor/components#capture-references-to-components

Sumitra Kumari Shaw

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