Last active
January 24, 2017 20:50
-
-
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.
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
| 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); |
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
| <!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