Created
August 4, 2019 20:15
-
-
Save YEK-PLUS/33d11e09a9536d3420dd28f64e26b512 to your computer and use it in GitHub Desktop.
React Redux Object Handler
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 from 'react'; | |
import PropTypes from 'prop-types'; | |
import { bindActionCreators } from 'redux'; | |
import { connect } from 'react-redux'; | |
//import App from '$/component/app'; | |
import * as UserActions from '$/state/actions/user'; | |
const mapStateToProps = state => ({ | |
logined: state.user.logined, | |
}); | |
function mapDispatchToProps(dispatch) { | |
return bindActionCreators(UserActions, dispatch); | |
} | |
const Counter = ({ | |
login, | |
logined, | |
}) => ( | |
<p> | |
Clicked: {logined?"a":"v"} times | |
<button onClick={login}>login ol</button> | |
{' '} | |
</p> | |
); | |
Counter.propTypes = { | |
login: PropTypes.func.isRequired, | |
logined: PropTypes.number.isRequired, | |
}; | |
export default connect(mapStateToProps, mapDispatchToProps)(Counter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment