Skip to content

Instantly share code, notes, and snippets.

@KonradSzwarc
Created June 12, 2020 22:59
Show Gist options
  • Select an option

  • Save KonradSzwarc/35fed2d4d34e3dcaf47166a65842984e to your computer and use it in GitHub Desktop.

Select an option

Save KonradSzwarc/35fed2d4d34e3dcaf47166a65842984e to your computer and use it in GitHub Desktop.
Custom implementation of the Material UI makeStyles function that uses a custom Theme type.
import makeMuiStyles from '@material-ui/styles/makeStyles';
import { ClassNameMap, Styles, WithStylesOptions } from '@material-ui/styles/withStyles';
import { Theme } from './types';
export const makeStyles = <Props extends {} | undefined = undefined, ClassKey extends string = string>(
styles: Styles<Theme, Props extends undefined ? {} : Props, ClassKey>,
options?: Omit<WithStylesOptions<Theme>, 'withTheme'>,
) => {
return makeMuiStyles(styles, options) as Props extends undefined
? (props?: any) => ClassNameMap<ClassKey>
: (props: Props) => ClassNameMap<ClassKey>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment