Skip to content

Instantly share code, notes, and snippets.

@dispalt
Created January 21, 2022 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dispalt/741121b9e90fc0969bcd5a2292a348f0 to your computer and use it in GitHub Desktop.
Save dispalt/741121b9e90fc0969bcd5a2292a348f0 to your computer and use it in GitHub Desktop.
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