# Creating additional react wrappers

**URL:** <https://discuss.kotlinlang.org/t/creating-additional-react-wrappers/5936>\
**Category:** Support\
**Created:** [December 23, 2017, 4:42am UTC](https://discuss.kotlinlang.org/t/creating-additional-react-wrappers/5936 "2017-12-23T04:42:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![animusnull](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@animusnull](https://discuss.kotlinlang.org/u/animusnull)\
**Post date:** [December 23, 2017, 4:42am UTC](https://discuss.kotlinlang.org/t/creating-additional-react-wrappers/5936/1 "2017-12-23T04:42:33Z")

</div>

I’m trying to look into adding wrappers for common react components. If there is already something for this, just skip the rest and paste a link. I’m specifically looking for react router, and redux.

I started a repository, and working on a very simple module to try and get used to the build system.

- [NPM Module](https://www.npmjs.com/package/react-md-spinner)
- [Code](https://github.com/animusnull/kotlin-react-extra/tree/master/kotlin-react-md-spinner)

I have the module auto completing in intellij, and seeing the proper types. But it’s failing to run.

> npm start

**Error**

```auto

src\app\App.kt:10:8: error: unresolved reference: reactextra
import reactextra.material.spinner.MDSpinner
       ^
src\app\App.kt:66:9: error: unresolved reference: MDSpinner
        MDSpinner()
        ^

```

The app itself is dead simple, just importing that library and calling the module.

Gives me the following. I’ve been going over the source for kotlin-wrapper and the outputted npm module. But there’s something I just be missing.

Secondly I wanted to ask about type matching with type script. I’m using ts2kt. But I’m curious about the best approach for [discriminated unions](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/index.d.ts#L7). I’m thinking a sealed class, but wasn’t 100% sure.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![bashor](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bashor/32/1431_2.png) [@bashor](https://discuss.kotlinlang.org/u/bashor)\
**Post date:** [December 25, 2017, 6:11pm UTC](https://discuss.kotlinlang.org/t/creating-additional-react-wrappers/5936/2 "2017-12-25T18:11:01Z")

</div>

Could you please provide a self-contained example to reproduce your problem?

Right now I can only guess, probably your library is invalid (Kotlin/JS library).

Also, [build.gradle](https://github.com/animusnull/kotlin-react-extra/blob/master/kotlin-react-md-spinner/build.gradle) doesn’t apply `kotlin2js` plugin and it’s strange.

Kotlin doesn’t have builtin union types, so the best solution to represent for TypeScript’s union type depends on the concrete case. For the provided [example](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/index.d.ts#L7) using sealed class sounds good, like:

```kotlin
external sealed class Action {
    object PUSH : Action() {}
    object POP : Action() {}
    object REPLACE : Action() {}
}

```

But to avoid crash at runtime you have to something like:

```nohighlight
const Action = {
   PUSH: 'PUSH',
   POP: 'POP',
   REPLACE: 'REPLACE'
}

```

---

<div class="post-metadata">

**Author:** ![animusnull](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@animusnull](https://discuss.kotlinlang.org/u/animusnull)\
**Post date:** [December 26, 2017, 5:24pm UTC](https://discuss.kotlinlang.org/t/creating-additional-react-wrappers/5936/3 "2017-12-26T17:24:44Z")

</div>

Thanks, @bashor for the response. Am I going about this the right way? I’m still wrapping my head around the Kotlin multi-module approach, and how best to build the web portion.

I was running gradle build from the top level directory. Which built each of the submodules. I followed the [kotlin-wrapper](https://github.com/JetBrains/kotlin-wrappers) for guidance. The output of the build is.

```auto
kotlin-react-md-spinner/build
├── classes
│ └── main
│ ├── kotlin-react-md-spinner
│ │ └── reactextra
│ │ └── material
│ │ └── spinner
│ │ └── spinner.kjsm
│ ├── kotlin-react-md-spinner.js
│ ├── kotlin-react-md-spinner.js.map
│ └── kotlin-react-md-spinner.meta.js

```

What I was doing.

```auto
gradle npm_publish

```

In a _create-react-kotlin-app_.

```auto
npm install kotlin-react-md-spinner

```

Modify the iml file to support the new library. Autocomplete, importing all works in Intellij. Run

```auto
npm start

```

Receive the prior error.

I removed the other modules and knocked it back to just one. I was going with a very simple module just to get my bearings. [It’s just this one Kotlin file.](https://github.com/animusnull/kotlin-react-extra/blob/master/kotlin-react-md-spinner/src/main/kotlin/reactextra/material/spinner/spinner.kt)

Thanks for the guidance on the union type.
