Home Can I remove mapStateToProps from my component having only mapDispatchToProps?
Reply: 1

Can I remove mapStateToProps from my component having only mapDispatchToProps?

Arjita Mitra
1#
Arjita Mitra Published in 2017-04-06 09:32:40Z

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 .

CodinCat
2#
CodinCat Reply to 2017-04-06 09:36:07Z

You can just pass a null to the connect:

export default connect(null, mapDispatchToProps)(Application);
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322728 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO