Skip to content

Instantly share code, notes, and snippets.

@rogeriochaves
Created June 16, 2017 21:51
Show Gist options
  • Save rogeriochaves/dc0854f64c76ee56ed5da91bd907685e to your computer and use it in GitHub Desktop.
Save rogeriochaves/dc0854f64c76ee56ed5da91bd907685e to your computer and use it in GitHub Desktop.
Redux implementation, basically
const React = require("react");
const ReactDOM = require("react-dom");
const reducer = (state, action) => {
switch (action) {
case "INCREMENT":
return state + 1;
case "DECREMENT":
return state - 1;
default:
return state;
}
};
const Counter = counter =>
<div>
<button onClick={dispatch("DECREMENT")}>-</button>
<h1>{counter}</h1>
<button onClick={dispatch("INCREMENT")}>+</button>
</div>;
const Main = props => Counter(props.state);
let actions = [];
const initialState = 0;
const dispatch = action => () => {
actions.push(action);
const state = actions.reduce(reducer, initialState);
ReactDOM.render(<Main state={state} />, document.getElementById("root"));
};
dispatch(null)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment