0

我有一个非常紧凑的 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 是什么以及我如何解决上述问题的建议都将不胜感激。谢谢你。

4

1 回答 1

2

我试过你发布的回购: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

并且,尝试发布完整的错误消息以备将来的错误,从“我们为您找到错误!”开始。线。这将有助于诊断很多。

于 2018-03-16T02:49:22.230 回答