Last active
November 9, 2018 02:14
-
-
Save webdevstar/c867e6bc206653a907e0ffadd1db1330 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); |
I know redux connect way now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
understood.
I have fixed redux connect issue.
Thanks