connect
@connect(({global, login, investment}) // state 解构=>({...global,...investment,...login}) // props 解构)// 将state绑定到props的counterconst mapStateToProps = (state)=> {return {counter: state}};export default connect(mapStateToProps, mapDispatchToProps)(Counter)// 即(state)=>({counter: state})export default connect((state)=>({counter: state}), mapDispatchToProps)(Counter)
prop-types
// 开发环境推荐使用,由于不具有强制约束的能力,生产环境建议使用插件优化掉Greeting.propTypes = {name: PropTypes.string,children: PropTypes.element.isRequired};Greeting.defaultProps = {name: 'Stranger'};
