Daniele B
09/21/2020, 11:48 PMMyElementsList
and MyElement
MyElementsList(content = {
MyElement(label = "a", value = "1")
MyElement(label = "b", value = "2")
MYElement(label = "c", value = "3")
})
what should be the definition of MyElementsList’s content
parameter to be able to pass a block of components ?
currently this is what I wrote, but it doesn’t seem to work:
fun RBuilder.ElementsList(content: (ReactElement) -> Unit) = child(ElementsList) {
attrs {
this.content = content
}
}
external interface ElementsListProps : RProps {
var content : (ReactElement) -> Unit
}
val ElementsList = functionalComponent<ElementsListProps> { props ->
div {
props.content
}
}
it compiles, but it just shows <div></div>
with no content
the MyElement
components are shown correctly if they are not enclosed in the MyElementsList
component, so it looks like the issue is in the MyElementsList
componentBahaa Kallas
09/22/2020, 10:00 AMfun RBuilder.ElementsList(content: RBuilder.() -> Unit) = child(ElementsList) {
attrs {
this.content = content
}
}
external interface ElementsListProps : RProps {
var content : RBuilder.() -> Unit
}
Bahaa Kallas
09/22/2020, 10:01 AMprops.content.invoke(this)
Daniele B
09/22/2020, 11:31 AMDaniele B
09/22/2020, 11:31 AMBahaa Kallas
09/22/2020, 11:32 AMDaniele B
09/22/2020, 11:33 AMBahaa Kallas
09/22/2020, 11:40 AMElementsList
a component defined in your kotlin code or imported through npm
(its javascript component) ?
for any component you create within your kotlin code you will never use the external
keyword
external
indicate that the following (class-function-interface) is defined in javascript and not in your kotlin codeDaniele B
09/22/2020, 12:00 PMElementsList
is defined in my Kotlin codeDaniele B
09/22/2020, 12:05 PMRBuilder.() -> Unit
and invoke(this)
and it works!Daniele B
09/22/2020, 12:05 PMDaniele B
09/22/2020, 12:08 PM