Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumit-gupta91/06a8ad3c09866fcde18885c02d21a33a to your computer and use it in GitHub Desktop.
Save sumit-gupta91/06a8ad3c09866fcde18885c02d21a33a to your computer and use it in GitHub Desktop.
A way to reduce complexity while exporting a component
import { bindActionCreators, compose } from 'redux';
const mapStoreToProps = data => ({
[createVendorPayoutFields.EXISTING_VENDOR]:
data[createVendorPayoutFields.EXISTING_VENDOR],
[createVendorPayoutFields.CREATED_VENDOR]:
data[createVendorPayoutFields.CREATED_VENDOR],
[createVendorPayoutFields.VENDOR_STEP_STATE]:
data[createVendorPayoutFields.VENDOR_STEP_STATE],
[createVendorPayoutFields.INTERNAL_NOTES]:
data[createVendorPayoutFields.INTERNAL_NOTES],
[createVendorPayoutFields.INVOICE_NUMBER]:
data[createVendorPayoutFields.INVOICE_NUMBER],
[createVendorPayoutFields.FUND_ACCOUNT]:
data[createVendorPayoutFields.FUND_ACCOUNT],
[createVendorPayoutFields.TOTAL_AMOUNT]:
data[createVendorPayoutFields.TOTAL_AMOUNT],
[createVendorPayoutFields.SUB_TOTAL]:
data[createVendorPayoutFields.SUB_TOTAL],
[createVendorPayoutFields.INVOICE_ISSUE_DATE]:
data[createVendorPayoutFields.INVOICE_ISSUE_DATE],
[createVendorPayoutFields.DUE_DATE]: data[createVendorPayoutFields.DUE_DATE],
[createVendorPayoutFields.DESCRIPTION]:
data[createVendorPayoutFields.DESCRIPTION],
[createVendorPayoutFields.TDS_CATEGORY]:
data[createVendorPayoutFields.TDS_CATEGORY],
[createVendorPayoutFields.INVOICE_ID]:
data[createVendorPayoutFields.INVOICE_ID],
});
const mapDispatchToProps = (dispatch) => ({
showErrorNotification: bindActionCreators(showErrorNotification, dispatch),
});
export default compose(
connect(mapStateToProps, mapDispatchToProps),
withWizardStep,
)(ReviewStep)
@prabhasjoshi
Copy link

Hi Sumit,
Yes this works,
A small suggestion-
in this section

export default compose(
  connect(mapStateToProps, mapDispatchToProps),
  withWizardStep,
 )(ReviewStep)

It should be

export default compose(
  connect(mapStateToProps, mapDispatchToProps),
  withWizardStep(mapStoreToProps),
 )(ReviewStep)

@sumit-gupta91
Copy link
Author

@prabhasjoshi this is a gist which tells the overall idea, if an HOC needs to be called with an argument call it with and argument, if it does not do not call it with arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment