关于higher-order-component
来源:5-5 react-redux连接react和redux

MeSKiL
2019-07-11
export default connect(function mapStateToProps(state) {
return {
counter:state.counter.count,
username:state.user.name,
}
},function mapDispatchToProps(dispatch) {
return {
add:(num) => dispatch({ type:'ADD',num }),
rename:(name) => dispatch({ type:'UPDATE',name })
}
})(Index)
既然是higher order component,这里可以用装饰器实现吗,感觉这里的代码太复杂了
写回答
1回答
-
Jokcy
2019-07-13
你可以把hoc当装饰器用,但你要用装饰器来实现hoc我倒是没见过
00
全栈进阶课程 React16.8+Next.js+Koa2一步到位开发Github
学习React/Next.js服务端渲染SSR同构设计方案,理解OAuth登录体系的实现原理
651 学习 · 311 问题
相似问题