Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Latest commit

 

History

History
24 lines (21 loc) · 772 Bytes

README.md

File metadata and controls

24 lines (21 loc) · 772 Bytes

React CSS modules: Partially applied styles HOC

In case you need to get a higher-order component with the styles already provided, you can do it that way:

import styles from './styles/Component.module.css';
import withStyles from 'react-css-modules-psh';

type OwnProps = { /* props. */ };

const Component: React.FC<OwnProps> = () => (
  <div styleName='Component' />
);

const withStylesApplied = withStyles(styles);
export default withStylesApplied;

You can also pass the result of the function to Redux compose function:

export default compose<React.Component<OwnProps>>(
  // ...,
  connect(mapStateToProps, mapDispatchToProps),
  withStyles(styles) // Need to be the first one.
)(Component);

That only works for functional components.