Last active
March 31, 2019 12:16
-
-
Save madan712/408c8fb25bf95b123cf35a4893a584a0 to your computer and use it in GitHub Desktop.
App.js - Simple React + Redux example
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
import React, {Component} from 'react'; | |
import './App.css'; | |
import {bindActionCreators} from 'redux'; | |
import {connect} from 'react-redux'; | |
import * as appAction from './AppAction'; | |
class App extends Component { | |
render() { | |
return ( | |
<div className="App"> | |
<button onClick={this.props.appAction.increment}>+</button> | |
Count: {this.props.count} | |
<button onClick={this.props.appAction.decrement}>-</button> | |
</div> | |
); | |
} | |
} | |
function mapStateToProps(state) { | |
return { | |
count: state.count | |
}; | |
} | |
function mapDispatchToProps(dispatch) { | |
return { | |
appAction: bindActionCreators(appAction, dispatch) | |
}; | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment