Skip to content

Instantly share code, notes, and snippets.

@airportyh
Last active January 24, 2017 20:50
Show Gist options
  • Select an option

  • Save airportyh/382aab8753ad81a05b3517e8a3462530 to your computer and use it in GitHub Desktop.

Select an option

Save airportyh/382aab8753ad81a05b3517e8a3462530 to your computer and use it in GitHub Desktop.
Quickstart template for getting started with learning basic React and Redex without all the cruft of setting up a build environment.
class MyThing extends React.Component{
increment() {
store.dispatch({ type: 'increment' });
}
decrement() {
store.dispatch({ type: 'decrement' });
}
render() {
return (
<div>
<label>Count: {this.props.value}</label>
<button onClick={this.increment}>+</button>
<button onClick={this.decrement}>-</button>
</div>);
}
}
function nextState(state = 1, action) {
if (action.type === 'increment') {
return state + 1;
} else if (action.type === 'decrement') {
return state - 1;
} else {
return state;
}
}
let store = Redux.createStore(nextState);
function render() {
ReactDOM.render(<MyThing value={store.getState()}/>, document.getElementById('root'));
}
render();
store.subscribe(render);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Babel Quickstart</title>
<script src="https://unpkg.com/babel-standalone@6/babel.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.6.0/redux.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel" src="app.js" data-presets="react"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment