-
-
Save nodetop/ab657dfb5db8a1a70789a229f1bd9e91 to your computer and use it in GitHub Desktop.
Redux connect example (dispatch & state)
This file contains 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 action from "../../Actions/MyAction"; | |
import Cartbox from "./Cartbox"; | |
import {bindActionCreators} from "redux"; | |
import {connect} from "react-redux"; | |
class Header extends Component { | |
constructor(props) { | |
super(props); | |
} | |
render () { | |
var carts = this.props.cart; | |
this.props.Action("1111"); | |
return ( | |
<div> | |
{ | |
carts.map((cart) => | |
<Cartbox key={cart.id} cart={cart}/> | |
) | |
} | |
</div> | |
); | |
} | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
Action : (e) => dispatch(action(e)) | |
} | |
} | |
const MyStatelessComponent = (state) => { | |
return ( | |
cart: state.cart | |
) | |
} | |
const WrappedComponent = connect(mapStateToProps, mapDispatchToProps)(Component); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment