Hi, how to recreate such code in Kotlin/React? ```...
# javascript
n
Hi, how to recreate such code in Kotlin/React?
Copy code
...
import TreeView from '@material-ui/lab/TreeView';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
...
<TreeView
      defaultCollapseIcon={<ExpandMoreIcon />}
    >
...
Wrappers for
TreeView
and
ExpandMoreIcon
exists, but how to recreate
defaultCollapseIcon={<ExpandMoreIcon />}
?
1
b
you need
class ExpandMoreIcon: RClass<ExpandMoreIconProps>
n
@Big Chungus mb I don't understand the meaning of
class
in your case, but my wrapper looks like this
Copy code
@file:JsModule("@material-ui/icons/ExpandMore")
@file:JsNonModule

package wrappers.materialui

import react.ComponentClass
import react.PropsWithChildren

@JsName("default")
external val ExpandMoreIcon: ComponentClass<PropsWithChildren>
RClass
is deprecated and now it's typeallias for
ComponentClass
. And my question is how to properly to pass it to props? ``````
In that case:
Copy code
...
TreeView {
  attrs {
    defaultExpandIcon = /* what we need here ? */
  }
...
}
b
Try
ExpandMoreIcon(props)
n
@Big Chungus In my case it's seems need to be
ExpandMoreIcon {}
and in case
Copy code
defaultExpandIcon = ExpandMpreIcon {}
I'm getting error:
Copy code
Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.
But if I pass it as
arrayOf(ExpandMoreIcon {} )
It just renders icon on top of all view (not in place where it needs to be) and doesn't change.
b
ExpandMpreIcon {}
is incorrect, because it just attaches the component to your parent component (not TreeView)
n
@Big Chungus my bad) but how to use
ExpandMoreIcons(props)
?
ExpandMoreIcons(jsObject())
gives me another error
Copy code
handler is not a function
b
I I wasn't saying that it should work for sure. Was just a guess 🙂
a
Did you try this?
Copy code
TreeView {
  attrs {
    defaultExpandIcon = createElement(ExpandMoreIcon)
  }
}
1
n
@andylamax Thx! Saving me again)
cheers 1
t
Since
pre.280
:
Copy code
val App = FC<Props>("App") {
    TreeView {    
        defaultExpandIcon = ExpandMoreIcon.create()
    }
}