Search code examples
react-reduxreact-css-modules

Using "connect" from Redux with react-css-modules


So far i've been using Redux "connect" to connect components with state, I export my components the following way:

export default connect(mapStateToProps, actions)(ComponentTitle);

I now want to use react-css-modules, but i'll have to do it using the following export in each component:

export default CSSModules(ComponentTitle, styles);

How can I export the component to have both functionalities?

Thanks :)


Solution

  • You can wrap your react component with css functionality before connect to redux.

    const ComponentWithCSS = CSSModules(ComponentTitle, styles);
    export default connect(mapStateToProps, actions)(ComponentWithCSS);