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
There's a lot of component [Parameter]s that use Func<Task> or Func<T, Task> instead of EventCallback or EventCallback<T> and I was wondering if there was any specific reason that is the case. Using EventCallback or EventCallback<T> will call Task IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object? arg) which for Microsoft.AspNetCore.Components.ComponentBase will automatically call StateHasChanged() on the handling component after the callback is executed which is, typically, the expected behaviour.
If callers do not want this behaviour they are able to bypass it by constructing their own EventCallback instance by using one of the EventCallback.Factory.Create methods with a non-null receiver (that is something other than the component) and a callback that does not have a .Target of the component (ie: it's not a closure of an instance method). However, this should not be required in most scenarios where either:
The caller cannot or does not wish to implement ShouldRender() (or any equivalent construct for components that don't inherit from Microsoft.AspNetCore.Components.ComponentBase).
-AND- Either:
Calling StateHasChanged() causes an infinite loop of event invocations. However, this would mostly be indicative of a bug where the setting of value by the parent component triggers a change notification of the child component for the same thing (or something that will trigger a change of the thing originally set by the parent.
Calling StateHasChanged() this frequently causes a significant performance impact.
Calling StateHasChanged() at that particular time has undesirable side-effects.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
There's a lot of component
[Parameter]s that useFunc<Task>orFunc<T, Task>instead ofEventCallbackorEventCallback<T>and I was wondering if there was any specific reason that is the case. UsingEventCallbackorEventCallback<T>will callTask IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object? arg)which forMicrosoft.AspNetCore.Components.ComponentBasewill automatically callStateHasChanged()on the handling component after the callback is executed which is, typically, the expected behaviour.If callers do not want this behaviour they are able to bypass it by constructing their own
EventCallbackinstance by using one of theEventCallback.Factory.Createmethods with a non-nullreceiver(that is something other than the component) and acallbackthat does not have a.Targetof the component (ie: it's not a closure of an instance method). However, this should not be required in most scenarios where either:ShouldRender()(or any equivalent construct for components that don't inherit fromMicrosoft.AspNetCore.Components.ComponentBase).StateHasChanged()causes an infinite loop of event invocations. However, this would mostly be indicative of a bug where the setting of value by the parent component triggers a change notification of the child component for the same thing (or something that will trigger a change of the thing originally set by the parent.StateHasChanged()this frequently causes a significant performance impact.StateHasChanged()at that particular time has undesirable side-effects.Beta Was this translation helpful? Give feedback.
All reactions