Search code examples
scalajs-react

What is the difference between build, buildU & buildSpec in Scalajs-react?


Can someone please explain the difference between the functions build, buildU and buildSpec for React components in scalajs-react and when to use one over the other ?


Solution

  • From https://github.com/japgolly/scalajs-react/blob/master/doc/USAGE.md

    Call build (or buildU) and when it compiles you will have a React component. […] If your props type is Unit, use buildU instead to be able to instantiate your component with having to pass () as a constructor argument.

    As for buildSpec, you can follow the types if you're interested but isn't mentioned because as @nafg says above, it's a low-level method that isn't relevant unless you already know what a "spec" is in the React world and you're doing something complicated with it. For what a React spec is, you can inspect the code and/or read about it in the React docs. Otherwise if you just want to create Scala React components, you only need to follow the instructions and examples and use build{,U}.