You can think of this as a template, here's a more ergonomic way
of doing the above:
object YourComponent1 {
@js.native
@JSImport("some-lib", "YourComponent1")
object JS extends ReactJsComponent
trait Props extends js.Object {
var param1: js.UndefOr[String] = js.undefined
}
def apply(props: Props)(children: ReactNode*) =
createElement(JS, props)(children:_*)
}
Since this is an imported component, the children do not need to
be in the Props trait directly.
How you hook up attributes and children values to your component is up to
you. In typescript, it is
common to define an interface that declares the allowed properties to be passed
in. The equivalent in scala.js are JS traits. You will want to make them
non-native JS traits so you can instantiate them.
If you need to include additional HTML specific props, you can use the vdom
package. Let's say you want to be able to pass in any HTML element properties to
your component.
A functional component is just a function. However, react can take a
function definition in its React.createElement API. Hence, you can import a
SFC and just "label" it a ReactJSComponent. Here's an example:
The 0 indicates that createElement takes no children and is provided
as API so you avoid appending a useless (). There are no children
to worry about so the children parameter list is dropped.