Skip to content

Instantly share code, notes, and snippets.

@YEK-PLUS
Created August 4, 2019 20:15
Show Gist options
  • Save YEK-PLUS/33d11e09a9536d3420dd28f64e26b512 to your computer and use it in GitHub Desktop.
Save YEK-PLUS/33d11e09a9536d3420dd28f64e26b512 to your computer and use it in GitHub Desktop.
React Redux Object Handler
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