Exporting From Scala to JS
Exporting a component for use in javascript environments requires you to export the function component. It is quite easy.
Since your function component already takes a js object as the props parameter, you can simple export the component using scala.js export API.
Here's the API. This is all you need to do:
The export can be placed anywhere in the code but it was included in the Component object for convenience.
If your Props
takes type parameters, you have to lock the type down
to create a stable value before exporting:
Exporting from scala.js and javascript bundling
When you bundle, say using webpack, your MyComponent
will be available at the
name WebPackLibName.MyComponent
because MyComponent was exported at the module level.
WebPackLibName is the name of the access point given to the webpacka configuration.
Since MyComponent was exported at the top level of this access point, the
dotted notation is all you need to access it.
If you want to use typescript as your "javascript" language for external-to-scala.js components, you will need to reproduce your typescript definitions for the parameters manually. Or you could write them in typescript and translate them into scala.js :-). It's up to you.