Skip to content

Instantly share code, notes, and snippets.

@dispalt
Created Jan 21, 2022
Embed
What would you like to do?
package slinky.core
import slinky.core.facade.ReactElement
import scala.scalajs.js
object FnComponent {
@inline def apply[P](fn: P => ReactElement)(implicit name: FunctionalComponentName): FunctionalComponent[P] = {
val ret: js.Function1[js.Object, ReactElement] = (obj: js.Object) => {
fn(obj.asInstanceOf[js.Dynamic].__.asInstanceOf[P])
}
if (scala.scalajs.LinkingInfo.developmentMode) {
ret.asInstanceOf[js.Dynamic].displayName = name.name
}
new FunctionalComponent[P](ret)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment