You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have added onmousemove to a div. It is bound to a method that does some calculation if the mouse is pressed but I have noticed that the component rerenders even when the metod is empty.
<div @onmousemove="@OnMouseMove">I'm a div content</div>
@code{
public void OnMouseMove(MouseEventArgs e){
//empty method but it causes a rerender
}
protected override void OnAfterRender(bool firstRender){
Debug.WriteLine("Rendered!")
}
}
I have tried to change onmousemove="@OnMouseMove" to onmousemove="@((e)=>OnMouseMove(e))" but I still get the same result.
Every time a mouse enters a div, "Rendered" is written to console meaning that the component has rerendered.
Why is this happening? Is there any workaround?
I'm using Blazor server side with ASP.NET Core version 3.0 and VisualStudio 2019.
The text was updated successfully, but these errors were encountered:
rborosak
changed the title
onmousemove causes component rerender
Blazor server side onmousemove causes component rerender
Nov 16, 2019
Blazor triggers an automatic re-render of a component as part of dispatching an event to it. If you want to alter this behavior you can override the ShouldRender method on ComponentBase to selectively choose when to re-render the component.
I have added onmousemove to a div. It is bound to a method that does some calculation if the mouse is pressed but I have noticed that the component rerenders even when the metod is empty.
I have tried to change onmousemove="@OnMouseMove" to onmousemove="@((e)=>OnMouseMove(e))" but I still get the same result.
Every time a mouse enters a div, "Rendered" is written to console meaning that the component has rerendered.
Why is this happening? Is there any workaround?
I'm using Blazor server side with ASP.NET Core version 3.0 and VisualStudio 2019.
The text was updated successfully, but these errors were encountered: