Scalajs-react 中的 build、buildU 和 buildSpec 有什么区别?

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

谁能解释一下 scalajs-react 中 React 组件的函数 buildbuildUbuildSpec 之间的区别,以及何时使用一个而不是另一个?

我自己不是 100% 确定,但看起来:

  • build 生成一个 scala 组件函数,它将你的道具类型的实例作为参数
  • buildU 适用于当您的道具类型为 Unit 时(这就是 U 所代表的意思),即您不需要任何道具对象,因此您可以在不提供 props 对象的情况下使用该组件。
  • buildSpec 我不太清楚,但它 returns 是 ReactComponentSpec 的一个实例,它有一个 js.native 注释,所以我怀疑它以某种方式给你 lower-level 访问 React 对象。

来自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.

至于 buildSpec,如果您有兴趣,可以按照类型进行操作,但未提及,因为正如@nafg 上面所说,这是一个不相关的 low-level 方法,除非您已经知道 React 世界中的 "spec" 是什么,而你正在用它做一些复杂的事情。对于 React 规范是什么,您可以检查代码 and/or 在 React 文档中阅读有关它的内容。否则如果你只是想创建 Scala React 组件,你只需要按照说明和示例并使用 build{,U}.