Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using a JS Higher-Order-Component (https://github.com/viktorbergehall/lcHOC) with scala-react-interface (sri)
import sri.core.{ComponentConstructor, ReactClass}
import scala.scalajs.js
import scala.scalajs.js.ConstructorTag
object LcHoc {
def apply[T <: ReactClass {type PropsType; type StateType}](params: js.UndefOr[LcHocParams] = js.undefined)
(implicit tag: ConstructorTag[T]): ComponentConstructor {
type ComponentType = T
type PropsType = T#PropsType
type StateType = T#StateType
} = LcHocJs(tag.constructor, params).asInstanceOf[
ComponentConstructor {
type ComponentType = T
type PropsType = T#PropsType
type StateType = T#StateType
}]
}
import sri.core.ReactClass
import scala.scalajs.js
import scala.scalajs.js.UndefOr
import scala.scalajs.js.annotation.{JSImport, ScalaJSDefined}
@ScalaJSDefined
trait LcHocParams extends js.Object {
val log: js.UndefOr[Log] = js.undefined
val flash: js.UndefOr[Boolean] = js.undefined
}
object LcHocParams {
@ScalaJSDefined
trait Log extends js.Object {
val use: js.UndefOr[Boolean] = js.undefined
val expanded: js.UndefOr[Boolean] = js.undefined
val renderCount: js.UndefOr[Boolean] = js.undefined
val state: js.UndefOr[Boolean] = js.undefined
val props: js.UndefOr[Boolean] = js.undefined
val timings: js.UndefOr[Boolean] = js.undefined
}
}
@js.native
@JSImport("lc-hoc", JSImport.Default)
object LcHocJs extends js.Function2[js.Dynamic, js.UndefOr[LcHocParams], ReactClass] {
override def apply(constructor: js.Dynamic, params: UndefOr[LcHocParams]): ReactClass = js.native
}
import sri.core.{ComponentP, CreateElement}
object Usage {
class MyComponent extends ComponentP[MyComponent.Props]
object MyComponent {
case class Props()
}
CreateElementJS[MySriComponent](LcHoc[MyComponent](), props= MyComponent.Props())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment