Antonio Pavicevac-Ortiz
Antonio Pavicevac-Ortiz

Reputation: 7739

How do I export multiple function calls in react?

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?

Upvotes: 0

Views: 219

Answers (1)

RIYAJ KHAN
RIYAJ KHAN

Reputation: 15292

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"

Upvotes: 1

Related Questions