Can you somehow cascade the @typeparam ?
For instance in this scenario, pass the TItem to the Child without specifying it
Expected behavior:
<Parent TItem="User">
<Child>
</Parent>
Current:
<Parent TItem="User">
<Child TItem="User">
</Parent>
Not yet, but it is supposed to be coming with .NET 6.
From the docs:
In .NET 6 Preview 2, Blazor can now infer generic type parameters from ancestor components. Ancestor components must opt in to this behavior. An ancestor component can cascade a type parameter by name to descendants using the
[CascadingTypeParameter]attribute. This attribute allows generic type inference to use the specified type parameter automatically with descendants that have a type parameter with the same name.
as of .NET 6.0 and later, you can use the [CascadingTypeParameter] attribute
Parent.razor
@attribute [CascadingTypeParameter(nameof(T))]
@typeparam T
Child.razor
@typeparam T // will be cascaded down from the parent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With