简体   繁体   中英

What should I pass to InvokeAsync when using EventCallback in blazor?

When using InvokeAsync in a EventCallback (without any type ie doesn't return anything) it still need an argument to invoke ir.

在此处输入图像描述

What should I pass there? Looks like I can pass anything that won't have any difference, but I'm not sure of that.

It also have a nice explanation for that argument

arg: The argument.

If you have a model you can pass it, or any property you use as a model. If not, you might try passing this . It won't do anything execution wise, but it will calm the compiler down and your code will run. The MS docs state that you should "Prefer strongly typed Event Callbacks", however sometimes that just doesn't make sense and you end up here.

One thought I had on the matter in keeping with the idea of reducing side effects, is that maybe we should use the strongly typed EventCallBack<bool> to kick out a bool that can be captured in the supplied method and used to verify something or other was complete, true, etc. The weakly typed version is in essence a "void" return on a method that is a code smell for side effects. I still don't know exactly where I land on the matter, and these are just my thoughts, take them with a grain of salt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM