React-JSS
React-JSS integrates one of the most popular css-in-js libraries, JSS, with React.
Setup
Here we will try to show the basics of how to get a theme going in react-jss.
Note: These are just examples, you can adapt them to work with your setup in however way you like and there is no 'single way' to work with style-genie.
You will want to have a theme
object so you can eventually pass it into ThemeProvider
The ThemeProvider
will simply accept the theme object we created above.
Which will make the theme
available throughout your app. But before that we need to create the styles using createUseStyles
.
We can then declare the component that will receive the styles. We call useTheme
to get the current instance of the theme, then we pass it to the useStyles
function we created above and then we are finally able to use the class inside the component.
Typescript
To use typescript with react0jss you will want to create the typings for your theme and export it, or make it globally available if you want.
Style-genie
exports all the types you will need for this. Most types are static, except Breakpoint
which is generic and can accept an object
type of signature { [key: string]: number }
in case you are using custom breakpoints.
You can, alternatively, generate the types from the theme
object as follows.
Then you have to pass the CustomTheme
type into the createUseStyles
function.
Last updated