I'm having trouble getting my external definitions...
# javascript
s
I'm having trouble getting my external definitions into react-native. I'm not a javascript expert, so I'm struggling a little bit. react-native uses babel to package things together via import statements, and those import statements pull code in from npm (I think). I've setup external definitions in Kotlin, but the Kotlin generated js can't find the js libraries from npm unless I manually edit the kotlin generated js file and add import statements at the top:
Copy code
import React from 'react';
import {AppRegistry, StyleSheet, Text, View} from 'react-native';
How should I be giving the kotlin code access to the npm libraries without manually editing the js file kotlin generates?
s
How you are accessing React in your application? Do you have something like that?
Copy code
@JsModule("react")
@JsNonModule
external object React
afaik,
val React = require("react").default
should be translated to
import React from 'react'
.
@JsModule
can be used to get
val React = require("react").default
. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-js-module/index.html
s
Copy code
package react

external object React {
  abstract class Component<P, S>(
      props: P? = definedExternally,
      context: Any? = definedExternally
  ) {
    abstract fun render(): dynamic
  }

  fun createElement(elementClass: dynamic, style: dynamic, children: dynamic): dynamic
}
I will try out those annotations. I didn't realize what they were for! Thanks 🙂
It took some fiddling, but it's finally working Sergey. Thanks a lot man. You've saved me a lot of time in the past few days 🙂
👍🏻 1