connect

    1. @connect(
    2. ({global, login, investment}) // state 解构
    3. =>
    4. ({...global,...investment,...login}) // props 解构
    5. )
    6. // 将state绑定到props的counter
    7. const mapStateToProps = (state)=> {
    8. return {
    9. counter: state
    10. }
    11. };
    12. export default connect(mapStateToProps, mapDispatchToProps)(Counter)
    13. // 即
    14. (state)=>({counter: state})
    15. export default connect((state)=>({counter: state}), mapDispatchToProps)(Counter)

    prop-types

    1. // 开发环境推荐使用,由于不具有强制约束的能力,生产环境建议使用插件优化掉
    2. Greeting.propTypes = {
    3. name: PropTypes.string,
    4. children: PropTypes.element.isRequired
    5. };
    6. Greeting.defaultProps = {
    7. name: 'Stranger'
    8. };