I created an app using the create-react-kotlin-app command and it loads in Chrome fine. I added the React Material UI package via NPM and that was successful. Now how do I use the Material UI module in my component?
Normally with JavaScript, it's a simple import Button from '@material-ui/core/Button' at the top of the component's file, but Kotlin doesn't like that.
How do I translate that line to Kotlin? I am not using Gradle.
The Kotlin way for importing dependencies is close to standard JS importing:
Based on Creating a simple React component with Kotlin.
Usually (as Kotlin is Java-based) it uses Gradle tool to handle dependencies:
And are referenced like above:
HomeView.kt:
ReactMarkdown.kt:
Based on: kotlin-fullstack-sample
In
create-react-kotlin-appadditionally faced the possibility of importing with@JsModule()annotation, while dependencies managing is handled in standard way viapackage.json:And can be also successfully used for JS libraries importing.
Another way would be to use
kotlinext.js.*:Which provides also
require(module: String)function.