Skip to content Skip to sidebar Skip to footer

Spreading Redux Actions Does Not Work In Mapdispatchtoprops

My mapDispatchToProps works like this: const mapDispatchToProps = dispatch => ({ getCourts: () => dispatch(courtActions.getCourts()), selectStyle: style => dispatch(c

Solution 1:

mapDispatchToProps takes an object too, which you can use instead of defining a function as mapDispatchToProps which would need to return functions that use dispatch.

According to the docs:

If an object is passed, each function inside it is assumed to be a Redux action creator. An object with the same function names, but with every action creator wrapped into a dispatch call so they may be invoked directly, will be merged into the component’s props.

Example

const mapDispatchToProps = courtActions;

Or you can simply pass courtActions as the second parameter to connect like

connect(mapStateToProps, courtActions)(MyComponent);

Solution 2:

as per my understanding mapDispatchToProps is function which takes dispatch as parameter and thats a dispatcher which dispatch massages to reducers. you cannot use like you want to use.

Post a Comment for "Spreading Redux Actions Does Not Work In Mapdispatchtoprops"