Created
September 25, 2020 18:03
-
-
Save erwstout/89b9b2f2eeaebea4e26ca105ec050b72 to your computer and use it in GitHub Desktop.
React-JSS HOC
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 { 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usecase:
When needing to access styles via hooks inside a traditional react component.