Created
November 23, 2019 01:58
-
-
Save jakewtaylor/e4219ab765659f15ce1fe1c87e87cf88 to your computer and use it in GitHub Desktop.
This file contains 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 { useMemo } from 'react'; | |
export const makeUseStyles = cb => (...args) => { | |
const styleObj = useMemo(() => cb(...args), args); | |
const styleSheet = useMemo(() => { | |
return Object.entries(styleObj).reduce((acc, [className, classes]) => { | |
acc[className] = classes.join(' '); | |
return acc; | |
}, {}); | |
}, [styleObj]); | |
return styleSheet; | |
}; |
This file contains 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 React from 'react'; | |
import { makeUseStyles } from '../styles/makeUseStyles'; | |
const useStyles = makeUseStyles(() => ({ | |
container: ['h-full'], | |
title: ['font-black'], | |
})); | |
export const Layout = ({ children }) => { | |
const styles = useStyles(); | |
return ( | |
<div className={styles.container}> | |
<header> | |
<h1 className={styles.title}>Hello World</h1> | |
</header> | |
{children} | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment