Created
June 8, 2018 19:59
-
-
Save mjs2600/599a99254ce86cb42248133c16e9a978 to your computer and use it in GitHub Desktop.
ReasonML Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type state = {count: int}; | |
type action = | |
| Increment | |
| Decrement; | |
let component = ReasonReact.reducerComponent("State"); | |
let make = _children => { | |
...component, | |
initialState: () => {count: 0}, | |
reducer: (action, state) => | |
switch (action) { | |
| Increment => ReasonReact.Update({count: state.count + 1}) | |
| Decrement => ReasonReact.Update({count: state.count - 1}) | |
}, | |
render: self => | |
<div> | |
<h1> | |
(ReasonReact.string("Count: " ++ string_of_int(self.state.count))) | |
</h1> | |
<button onClick=(_event => self.send(Increment))> | |
(ReasonReact.string("+")) | |
</button> | |
<button onClick=(_event => self.send(Decrement))> | |
(ReasonReact.string("-")) | |
</button> | |
</div>, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment