Add OnMounted
component lifecycle event
#49497
Labels
area-blazor
Includes: Blazor, Razor Components
Needs: Author Feedback
The author of this issue needs to respond in order for us to continue investigating this issue.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I want to invoke JavaScript after a pre-rendered server component has been mounted in the browser. But I can't find a way to do it.
It used to be (with Razor Pages) that you did it in
OnAfterRender
which ran twice, and you checkedfirstRender
. For Blazor Server, that meant that if it was true then you where running in the browser and was able to invoke JavaScript. While for WebAssembly you had to check for it to be false.In Blazor Server in .NET 8, it doesn't work that way.
And this behavior is reasonable. It makes sense that when you have pre-rendered a server component you have already rendered it, and there is no need to call the lifecycle event method again.
To me it makes the most sense to add a new event method indicating that the code has been materialized or "mounted" in the browser.
Describe the solution you'd like
Add an
OnMounted()
lifecycle method that is executed afterOnAfterRender
has been executed the first time and the component has been added to the Browsers DOM and the SignalR connection is up and runningThis will enable the to execute logic when the component has been mounted - like invoking JavaScript,
Additional context
No response
The text was updated successfully, but these errors were encountered: