Does anyone have an example of using the kotlin-re...
# javascript
n
Does anyone have an example of using the kotlin-react library with existing Javascript React components? I’m completely baffled as to how to instantiate a JS react component from Kotlin, since the
child
method takes a KClass or reified type parameter of the child component to construct, neither of which is available for extern interfaces
l
@Filipp Riabchun should be able to answer that
f
You should declare your import as
Copy code
@JsModule("react-something")
external val ReactSomething: RClass<dynamic>
then you'll be able to call it directly in your builder like you do with
div
and other builtins
Copy code
fun RBuilder.foo {
  ReactSomething {
    // not typesafe yet
    attrs.foo = "bar"

    +"child text"
  }
}
n
👍
f
Then you can add some typesafety by replacing
dynamic
with props spec:
Copy code
external interface ReactSomethingProps {
  // should be var not val, as we will assign it
  var foo: String
}

@JsModule("react-something")
external val ReactSomething: RClass<ReactSomethingProps>
n
Nice