Skip to content
Discussion options

You must be logged in to vote

The reason the method-group version blows up is simple: when you write

@onclick="_myComponentRef.ShowComponent"

Blazor tries to bind that delegate immediately, during render. It wants a real, fully initialized component reference at that exact moment. But your _myComponentRef isn’t wired up yet. The render handle for the referenced component isn’t assigned, the instance isn’t connected to the render tree, and Blazor basically goes “nope.”

The lambda version:

@onclick="() => _myComponentRef.ShowComponent()"

doesn’t get evaluated at render time. It’s just a little box that Blazor stores and only opens when you click the button. By that time, the component ref has been assigned, the render…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@patriksvensson
Comment options

@yassine-krichen
Comment options

@patriksvensson
Comment options

Answer selected by patriksvensson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants