Skip to content

Instantly share code, notes, and snippets.

@lilpolymath
Last active July 29, 2020 12:23
Show Gist options
  • Save lilpolymath/98bb40e1bffe5eac9cdde17053e1059e to your computer and use it in GitHub Desktop.
Save lilpolymath/98bb40e1bffe5eac9cdde17053e1059e to your computer and use it in GitHub Desktop.
Sample on how CSS Modules works.
import * as React from 'react';
import styles from './style.module.css';
export default function Container({ children, as = 'div', ...props }) {
const Component = as;
const style = styles.container + ' ' + props.styles;
return (
<Component className={style} {...props}>
<div className={styles.wrapper}>{children}</div>
</Component>
);
}
@lilpolymath
Copy link
Author

lilpolymath commented Jul 29, 2020

For usage check this

You notice that it takes the Component's name and appends some template literal which is randomly generated to prevent clashes when you reuse it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment