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>
|
2017-11-28 13:15:03 +00:00
|
|
|
<p> (ReasonReact.stringToElement(countMsg)) </p>
|
|
|
|
<button onClick=(self.reduce((_event) => Add))>
|
|
|
|
(ReasonReact.stringToElement("Add"))
|
|
|
|
</button>
|
2017-08-27 20:13:35 +00:00
|
|
|
</div>
|
|
|
|
}
|
2017-11-28 13:15:03 +00:00
|
|
|
};
|