Skip to content

Instantly share code, notes, and snippets.

@jakewtaylor
Created November 23, 2019 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakewtaylor/e4219ab765659f15ce1fe1c87e87cf88 to your computer and use it in GitHub Desktop.
Save jakewtaylor/e4219ab765659f15ce1fe1c87e87cf88 to your computer and use it in GitHub Desktop.
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;
};
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