>我有一个非常紧凑的 ReasonReact reducer 组件,它有一个组件、initialState、reducer、action 和 render 函数,如下所示:
type actions =
| DoNothing;
let component = ReasonReact.reducerComponent("ShowHide");
let make = (~name, _children) => {
...component,
initialState: () => 0, /* here, state is an `int` */
reducer: (action, state) =>
switch action {
| DoNothing => ReasonReact.NoUpdate;
},
render: (self) => {
let greeting =
"Hello: " ++ name ++ ". You've clicked the button " ++ string_of_int(self.state) ++ " time(s)!";
<div></div>
}
};
我正在尝试使用 ReactDOMRe.renderToElementWithId
函数在我的 app.re 文件中渲染:
<div id = "RenderShowHide"></div>
ReactDOMRe.renderToElementWithId(<ShowHide name="hello" />, "RenderShowHide")
但是,Reason/Bucklescript 编译器抱怨如下:
This has type:
(ReasonReact.reactElement, string) => unit
But somewhere wanted:
at <anonymous>actElement
但是,我很难理解什么是actElement。任何关于什么是actElement的建议,以及我如何解决上述问题,将不胜感激。谢谢。
我尝试了您发布的存储库:https://github.com/CharlieGreenman/reason-react-razroo
npm install
bsb -make-world
我收到以下错误消息:
We've found a bug for you!
/Users/yawar/src/reason-react-razroo/src/app.re 16:9-40
14 ┆ </div>
15 ┆ <p className="App-intro">
16 ┆ ReactDOMRe.renderToElementWithId(<ShowHide name="hello"/>, "index")
17 ┆ (ReasonReact.stringToElement("To get started, edit"))
18 ┆ <code> (ReasonReact.stringToElement(" src/app.re ")) </code>
This has type:
(ReasonReact.reactElement, string) => unit
But somewhere wanted:
ReasonReact.reactElement
看起来您的构建工具中的某些内容正在吞噬部分错误消息。主要问题在 l. 16;如果您摆脱该行,错误将消失。如果要呈现ShowHide
组件,请将该行更改为仅文本 JSX,而不是对 ReactDOMRe.renderToElementWithId
的调用。
我有两个更一般的建议;尝试坚持使用 bsb 提供的 React 骨架项目,除非你是专家级的,因为它更简单,支持得更好:
bsb -init my-project -theme react
并且,尝试发布整个错误消息以备将来出现错误,从"我们为您找到了错误!这将有助于诊断很多。