Error: This expression has type unit but an expression was expected of type

reasonreact

#1

Hi all
I have the following code, that I do not figure out, why there is an error:

let make = (_children) => {
  ...component,
  didMount: self => self.send(Mount),
  initialState: () => {count: 0},
  reducer: (action, state) => {
    switch (action) {
    | Mount => ReasonReact.Update({...state, count: state.count + 1})
    };
  },
  render: self => {
    <div> 
     { ReasonReact.stringToElement(string_of_int(self.state.count)) }
    </div>;
  },
};

It says, that is something wrong with didMount lifecycle:

Error: This expression has type unit but an expression was expected of type
         ReasonReact.update ('a,  'b,  'c)  

There is a warning about:

Warning 23: all the fields are explicitly listed in this record: the 'with' clause is useless.

Thanks


#2

didMount expects you to return ReasonReact.update ('a, 'b, 'c) but self.send return an unit.

Fix:

didMount: self => {
  self.send(Mount);
  ReasonReact.NoUpdate();
},

your state record only contains count field so no need to spread.