Hi, I just started to use react+kotlin using creat...
# react
d
Hi, I just started to use react+kotlin using create-react-kotlin-app, I have one question: can I use existing module (eg. react-bootstrap) in my project?
f
Sure. You can start with this:
Copy code
@JsModule("react-bootstrap/lib/Alert")
external val Alert: RClass<dynamic>

// then somewhere in your components
Alert {
  attrs {
    bsStyle = "warning"
  }

  +"Got an error"
}
Which roughly corresponds to this JSX:
Copy code
<Alert bsStyle = "warning">Got an error</Alert>
Later, you can add some type-safety by replacing
dynamic
with some props spec based on propTypes or documentation (https://react-bootstrap.github.io/components.html#alerts)
Copy code
external interface AlertProps: RProps {
  var bsClass: string
  var bsStyle: string
  var closeLabel: string
  var onDismiss: () => Unit
}

@JsModule("react-bootstrap/lib/Alert")
external val Alert: RClass<AlertProps>
Then if you try to do something like this, you'll get type errors at compile time
Copy code
Alert {
  attrs {
    bsStyle = 100 // invalid value
    foo = true // invalid property
  }
}
d
thanks! Really interesting! Now I’m working, but tonight I will try 🙂
Hi Filipp, I’m sorry but it doesn’t work for me 😞 It adds the element to the UI, but if I declare an attribute I received the following error:
Copy code
src/contact/ContactList.kt:46:21: error: unresolved reference: bsStyle
                    bsStyle = “warning”
My project was created with create-react-kotlin-app
while using the second exaple, adding some type-safety by replacing `dynamic`type-safety, it works.