Browser console error with @ref function call
See original GitHub issueWhen calling a function belonging to an @ref
element, an error can occur depending on the format of the function call. Does @onclick
not always expect C# code?
<!--Runs as expected-->
<button type="button" @onclick="@(() => myComponent.DoSomething())">Do Something</button>
<!--Produces an error in the browser console on load (though this is the typical format for a function call with no parameters)-->
<button type="button" @onclick="myComponent.DoSomething">Do Something</button>
<MyComponent @ref="myComponent" />
@code {
private MyComponenet myComponent { get; set; }
}
Error
Delegate to an instance method cannot have null ‘this’
IDE: VS Mac 8.7.0.1077
dotnet --info
:
.NET Core SDK (reflecting any global.json):
Version: 3.1.300
Commit: b2475c1295
Runtime Environment: OS Name: Mac OS X OS Version: 10.15 OS Platform: Darwin RID: osx.10.15-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.300/
Host (useful for support): Version: 3.1.4 Commit: 0c2e69caa6
.NET Core SDKs installed: 3.1.100 [/usr/local/share/dotnet/sdk] 3.1.101 [/usr/local/share/dotnet/sdk] 3.1.102 [/usr/local/share/dotnet/sdk] 3.1.200 [/usr/local/share/dotnet/sdk] 3.1.201 [/usr/local/share/dotnet/sdk] 3.1.202 [/usr/local/share/dotnet/sdk] 3.1.300 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Thanks @mrlife … I’ll open an issue for a little call out on that.
So maybe the distinction I was missing is purely about direct reference vs lambda of an @ref property, where direct is processed on component load and lambda is processed only when needed?