Skip to content

Instantly share code, notes, and snippets.

@heygema
Created May 30, 2018 05:49
Show Gist options
  • Save heygema/91e1c6f8113a01ee14bda6b4bdf9ea9b to your computer and use it in GitHub Desktop.
Save heygema/91e1c6f8113a01ee14bda6b4bdf9ea9b to your computer and use it in GitHub Desktop.
GlobalState.re
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>
};
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