Paul SOUTEYRAT
04/17/2021, 11:11 AMinterface MyGenericCompProps<T> : RProps
fun <T> myGenericComp() = { props: MyGenericCompProps<T> ->
buildElement {
div {
+"Generic component"
}
}
}
val genericCompContainer = functionalComponent<RProps> {
child(myGenericComp<Any>())
}
But I am not sure if it's a good way to make a component.
Do any of you see issues with my example ?turansky
04/17/2021, 11:57 AMexternal interface MyGenericProps<T>: RProps
fun <T> RBuilder.myGenericComp(props: MyProps<T>) {
// add elements
}
Paul SOUTEYRAT
04/17/2021, 12:13 PMPaul SOUTEYRAT
04/17/2021, 12:19 PMturansky
04/17/2021, 12:24 PMPaul SOUTEYRAT
04/17/2021, 1:12 PMturansky
04/17/2021, 1:21 PMAnyway, would you mine to explain why I should prefer your method over mine?Do you mean variants with component and without component?
turansky
04/17/2021, 1:22 PMPaul SOUTEYRAT
04/17/2021, 1:29 PMDo you mean variants with component and without component?No, I don't. I was talking about variants between what I originally posted (i.e. a lambda functional component) and what you provided (i.e. a standard generic functional component).
fun <T> myGenericComp() = { props: MyGenericCompProps<T> ->
buildElement {
div {
+"Generic component"
}
}
}
turansky
04/17/2021, 1:37 PMmyGenericComp
in your example - new component every call
AFAIK Kotlin will create anonymous function for lambda, but it’s implementation details, which only hide problemPaul SOUTEYRAT
04/17/2021, 1:49 PM