scalajs-reaction

scala.js facade in the spirit of ReasonReact

[object Object]

Easy to Use

scalajs-reaction uses reactjs function components and hooks to make component creation and use easy. You use common, everyday, highly inferable scala idoms--no macros or tricks.

[object Object]

Focus on What Matters

Focus on creating great web applications not on the framework or making the interop work.

[object Object]

Powered by React

It is all reactjs underneath the hood and interop is a breeze so you can drop down to js or typescript any time you want.

It is easy to create a component. The code below creates a functional component that takes zero args.

val HelloWorld: ReactFC0 = () => div("hello world")

A functional component that takes props (one argument) with a mandatory [name] property is

object MyComponent {
trait Props extends js.Object {
val name: String
}
val render: ReactFC[Props] = props => div("hello " + props.name)
render.displayName("MyComponent")
def apply(props: Props) = render.elementWith(props)
}

By defining an apply method (or not) you decide how component users create elements.

To use MyComponent, we just need to create it. Creating an element is as natural and easy as calling it's apply function.

// scala code
div(
MyComponent(new Props {
val name = "world"
})
)

You can create custom Props creation methods if you choose. Everything above is just pure scala.js--not tricks or macros. Type inference is very good and it is a natural scala programming style.