Created
May 30, 2018 05:49
-
-
Save heygema/91e1c6f8113a01ee14bda6b4bdf9ea9b to your computer and use it in GitHub Desktop.
GlobalState.re
This file contains hidden or 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
let component = ReasonReact.statelessComponent("Home"); | |
let make = _children => { | |
...component, | |
render: _self => | |
<div className=Style.container> | |
<Store> | |
...( | |
({state, send}) => | |
<div> | |
<h1> (ReasonReact.stringToElement(state.text)) </h1> | |
<button onClick=(_e => send(Store.ChangeWorld))> | |
(ReasonReact.stringToElement("change")) | |
</button> | |
</div> | |
) | |
</Store> | |
</div> | |
}; |
This file contains hidden or 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 action = | |
| ChangeWorld; | |
type state = {text: string}; | |
let initialState = () => {text: "world"}; | |
let reducer = (action, state) => | |
switch action { | |
| ChangeWorld => | |
ReasonReact.Update( | |
state.text === "world" ? {text: "hello"} : {text: "world"} | |
) | |
}; | |
let component = ReasonReact.reducerComponent("Store"); | |
let make = children => { | |
...component, | |
initialState, | |
reducer, | |
render: self => children(self) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment