Reputation: 348
In order to access to the props
of the component inside the mapDispatchToProps
i chained my connect like so
export default connect(mapStateToProps, null)(connect(mapStateToProps, mapDispatchToProps)(MyComponent));
And then i manage to access to the props inside the mapDispatchToProps like so
const mapDispatchToProps = (dispatch,ownProps) => {
const myProp = ownProps.theProp
}
Is it a bad things to do ? Any alternative exists ?
Upvotes: 0
Views: 125
Reputation: 12174
Is it a bad things to do?
IMO, It is certainly bad. connect()
is an HOC. connect(...)(connect(...)(MyComponent))
is redundant.
Any alternative exists ?
Use mergeProps
instead or break the components properly and use redux-saga
to use a common interaction point (the redux store).
Upvotes: 2
Reputation: 497
The correct way to connect mapDispatch to props and mapStateToProps is like this:
export default connect(mapStateToProps, mapDispatchToProps)(MetaDataTaggingApp);
Also I don't think you should have to access props in mapDispatchToProps. mapDispatchToProps is basically just telling your component which dispatch actions it's allowed to use.
const mapDispatchToProps = {
aReduxAction,
anotherReduxAction
}
If you need to pass props into these dispatches, it should be when you are invoking them.
Upvotes: 0