Last active
July 29, 2020 12:23
-
-
Save lilpolymath/98bb40e1bffe5eac9cdde17053e1059e to your computer and use it in GitHub Desktop.
Sample on how CSS Modules works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.