Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I remove mapStateToProps from my component having only mapDispatchToProps?

I don't need mapStateToProps in my component but I need mapDispatchToProps -

const mapDispatchToProps = dispatch =>     ({         myCallBack(passFunc, passDirFunc) {             dispatch(                 actions.setSideNavAction(passFunc, passDirFunc)             )         }     })  

If I remove mapStateToProps completely and use connect like -

export default connect(mapDispatchToProps)(Application); 

then getting error - Uncaught (in promise) TypeError: dispatch is not a function.

Is it mandatory to keep an empty mapStateToProps.

const mapStateToProps = state =>     ({      }) 

Please clarify .

like image 678
Arjita Mitra Avatar asked Apr 06 '17 09:04

Arjita Mitra


People also ask

Can I mapDispatchToProps without mapStateToProps in Redux?

Can I mapDispatchToProps without mapStateToProps in Redux? ​ Yes. You can skip the first parameter by passing undefined or null .

What do mapStateToProps and mapDispatchToProps actually do?

The mapStateToProps and mapDispatchToProps deals with your Redux store's state and dispatch , respectively. state and dispatch will be supplied to your mapStateToProps or mapDispatchToProps functions as the first argument.

Is it possible to dispatch an action without using mapDispatchToProps?

Without mapDispatchToPropsNotice that the component receives a dispatch prop, which comes from connect() , and then has to use it directly to trigger the actions.

Can I use mapStateToProps in functional component?

You can definitely use mapStateToProps with a functional component, the same way you would with a class component.


1 Answers

You can just pass a null to the connect:

export default connect(null, mapDispatchToProps)(Application); 
like image 166
CodinCat Avatar answered Sep 21 '22 16:09

CodinCat