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 ?
- 3,619
- 7
- 36
- 58
2 Answers
From https://github.com/japgolly/scalajs-react/blob/master/doc/USAGE.md
Call
build(orbuildU) and when it compiles you will have a React component. […] If your props type isUnit, usebuildUinstead 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}.
- 1,319
- 8
- 18
Not 100% sure myself but it seems:
buildproduces a scala component function that takes an instance of your props type as a parameterbuildUis for when your props type isUnit(that's what the U stands for), i.e., you don't need any props object, so you can use the component without providing a props object.buildSpecI'm less clear about, but it returns an instance ofReactComponentSpecwhich has ajs.nativeannotation, so I suspect it somehow gives you lower-level access to the React object.
- 2,424
- 27
- 25