Last active
October 3, 2018 16:53
-
-
Save hanford/05905d85cd571559268cd4c19e3feb80 to your computer and use it in GitHub Desktop.
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 = | |
| Add | |
| Subtract; | |
module Counter = { | |
let component = ReasonReact.reducerComponent("Counter") | |
let make = _children => { | |
...component, | |
initialState: () => { count: 0 }, | |
reducer: (action, state) => { | |
switch (action) { | |
| Add => ReasonReact.Update({ count: state.count + 1 }) | |
| Subtract => ReasonReact.Update({ count: state.count - 1 }) | |
} | |
}, | |
render: self => { | |
let message = "Count #" ++ string_of_int(self.state.count); | |
<div> | |
<div>(message |> ReasonReact.string)</div> | |
<button onClick=(_event => Add |> self.send)>(ReasonReact.string("Add"))</button> | |
<button onClick=(_event => Subtract |> self.send)>(ReasonReact.string("Subtract"))</button> | |
</div> | |
} | |
}; | |
}; | |
ReactDOMRe.renderToElementWithId(<Counter />, "preview"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment