Skip to content

Instantly share code, notes, and snippets.

@whroman
Last active May 11, 2017 09:19
Show Gist options
  • Save whroman/394b280a2efcd21056b95c129acf09c1 to your computer and use it in GitHub Desktop.
Save whroman/394b280a2efcd21056b95c129acf09c1 to your computer and use it in GitHub Desktop.
// SomeConnectedComponent.js
// ============================
// Before:
const mapDispatchToProps = (dispatch) => ({
dispatch,
})
const mapStateToProps = (state) => ({
resumable: (state.exam.attempt.attemptUUID !== null),
const mergeProps = (stateProps, dispatchProps, ownProps) => {
const startOrResume = (stateProps.resumable) ?
examResumeAndUpdateAttempt : examStartAndCreateAttempt
return Object.assign(
{},
dispatchProps,
ownProps,
{
startOrResume,
dispatch: dispatchProps.dispatch,
}
)
}
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Preparation)
// ============================
// After:
const mapStateToProps = (state) => {
const resumable = state.exam.attempt.attemptUUID !== null
const startOrResume = resumable ? examResumeAndUpdateAttempt : examStartAndCreateAttempt
return { startOrResume }
}
export default connect(mapStateToProps)(Preparation)
// ============================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment