0

I have this in my file:

 export default withAuth(authOptions)(ProfilePage);

But I also need to export this:

function mapStateToProps (state) {
  const { isLoggedIn } = state
  return { isLoggedIn}
}
const mapDispatchToProps = dispatch =>
  bindActionCreators({ logInUser }, dispatch)

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ProfilePage)

I can I combine them so they both work?

2
  • 1
    Why not this? export default withAuth(authOptions)(connect( mapStateToProps, mapDispatchToProps )(ProfilePage)); Commented Oct 12, 2019 at 6:26
  • glad it helped! Here is why it works since in withAuth(authOptions)(SOME-COMPONENT) we need to provide component,also connect()() returns a component putting it inplace of SOME-COMPONENT solves our issue. Commented Oct 12, 2019 at 6:38

1 Answer 1

1

You can using JS#named export.

export const  mapStateToProps =  (state)=> {
  const { isLoggedIn } = state
  return { isLoggedIn}
}
export const mapDispatchToProps = dispatch =>bindActionCreators({ logInUser }, dispatch)

now import it in other file

//test.js

import ProfilePage,{mapStateToProps ,mapDispatchToProps} from "path_to_file"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.