2017-09-30 20:02:45 +00:00
|
|
|
type action =
|
|
|
|
| Add;
|
|
|
|
|
2017-11-28 13:15:03 +00:00
|
|
|
let component = ReasonReact.reducerComponent("Counter");
|
2017-09-30 20:02:45 +00:00
|
|
|
|
2017-11-28 13:15:03 +00:00
|
|
|
let make = (_children) => {
|
2017-08-27 20:13:35 +00:00
|
|
|
...component,
|
2017-11-28 13:15:03 +00:00
|
|
|
initialState: () => 0,
|
|
|
|
reducer: (action, state) =>
|
2017-09-30 20:02:45 +00:00
|
|
|
switch action {
|
2017-11-28 13:15:03 +00:00
|
|
|
| Add => ReasonReact.Update(state + 1)
|
2017-09-30 20:02:45 +00:00
|
|
|
},
|
2017-11-28 13:15:03 +00:00
|
|
|
render: (self) => {
|
|
|
|
let countMsg = "Count: " ++ string_of_int(self.state);
|
2017-08-27 20:13:35 +00:00
|
|
|
<div>
|
2018-09-02 23:38:54 +00:00
|
|
|
<p> (ReasonReact.string(countMsg)) </p>
|
|
|
|
<button onClick=(_event => self.send(Add))>
|
|
|
|
(ReasonReact.string("Add"))
|
2017-11-28 13:15:03 +00:00
|
|
|
</button>
|
2017-08-27 20:13:35 +00:00
|
|
|
</div>
|
|
|
|
}
|
2018-09-02 23:38:54 +00:00
|
|
|
};
|