Skip to content

Instantly share code, notes, and snippets.

@erwstout
Created September 25, 2020 18:03
Show Gist options
  • Save erwstout/89b9b2f2eeaebea4e26ca105ec050b72 to your computer and use it in GitHub Desktop.
Save erwstout/89b9b2f2eeaebea4e26ca105ec050b72 to your computer and use it in GitHub Desktop.
React-JSS HOC
import { createUseStyles, useTheme } from "react-jss";
import { WithStyles as WithStylesI, Theme } from "../../types";
export const WithStyles = ({ children, styles }: WithStylesI) => {
const useStyles = createUseStyles((theme: Theme) => styles(theme));
const theme = useTheme();
const classes = useStyles({ theme });
return children(classes);
};
// USAGE:
// <WithStyles styles={styles}>
// ....
// </WithStyles>
@erwstout
Copy link
Author

Usecase:

When needing to access styles via hooks inside a traditional react component.

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