0

In a third party library react-native-fbsdk-next I have a file FBAccessToken.ts The class below has a few ordinary members and a static member function.

class FBAccessToken {

  accessToken: string;
  permissions: Array<string>;

  static getCurrentAccessToken() {
    return new Promise<FBAccessToken | null>((resolve) => {
    ...
    }
  }
}

export default FBAccessToken;

I need to import both the class members as well as the static function.

My strategy is to use a scala class and a companion object like so

  @native
  @JSImport("react-native-fbsdk-next", "FBAccessToken")
  class FBAccessToken extends js.Object {
    def accessToken: String = native
    def permissions: Array[String] = native
  }

  @native
  @JSImport("react-native-fbsdk-next", "FBAccessToken")
  object FBAccessToken extends js.Object {
    def getCurrentAccessToken: Promise[FBAccessToken | Null] = native
  }

But the static function to companion object import seems to not work. sbt fastOptJs works but on running the app in a simulator I get

TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[4], "react-native-fbsdk-next").FBAccessToken.getCurrentAccessToken')

What am I doing wrong?

1 Answer 1

2

FBAccessToken is exported under the default export in the JavaScript library:

export default FBAccessToken;

and not under its own name "FBAccessToken".

Therefore, when importing it from Scala.js, you have to use JSImport.Default as the second argument ot @JSImport:

@JSImport("react-native-fbsdk-next", JSImport.Default)

This applies both to the class and to the object

Sign up to request clarification or add additional context in comments.

1 Comment

After doing the above the, it fails again on the static function import when it is called. See - stackoverflow.com/questions/73646551/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.