【发布时间】:2019-10-12 06:23:32
【问题描述】:
我的文件中有这个:
export default withAuth(authOptions)(ProfilePage);
但我还需要导出这个:
function mapStateToProps (state) {
const { isLoggedIn } = state
return { isLoggedIn}
}
const mapDispatchToProps = dispatch =>
bindActionCreators({ logInUser }, dispatch)
export default connect(
mapStateToProps,
mapDispatchToProps
)(ProfilePage)
我可以将它们结合起来,让它们都起作用吗?
【问题讨论】:
-
为什么不这样呢? export default withAuth(authOptions)(connect( mapStateToProps, mapDispatchToProps )(ProfilePage));
-
很高兴它有帮助!这就是为什么它起作用的原因,因为在 withAuth(authOptions)(SOME-COMPONENT) 中我们需要提供组件,而且 connect()() 返回一个将其替换为 SOME-COMPONENT 的组件解决了我们的问题。
标签: reactjs react-redux es6-modules module.exports