preact-jss-hook
v2.1.2
Published
JSS integration with Preact
Downloads
16
Readme
preact-jss-hook
JSS integration with Preact.
Installation
npm i preact-jss-hook
Usage
Basic Example
import { createUseStyles } from 'preact-jss-hook'
const useStyles = createUseStyles({
root: {
color: 'red'
}
})
export default () => {
const { classes } = useStyles()
return (
<div className={classes.root}>
Red block
</div>
)
}
JSS Provider
import { JssProvider } from 'preact-jss-hook'
import { create } from 'jss'
const jss = create()
const theme = {
primaryColor: 'red'
}
export default () => (
<JssProvider
jss={jss} // optional
theme={theme} // optional
>
Children
</JssProvider>
)
Using Theme
import { createUseStyles } from 'preact-jss-hook'
const useStyles = createUseStyles((theme) => ({
root: {
color: theme.primaryColor
}
}))
export default () => {
const { classes, theme } = useStyles()
return (
<div className={classes.root}>
Red block
</div>
)
}
Using HOC
import { createWithStyles } from 'preact-jss-hook'
const withStyles = createWithStyles((theme) => ({
root: {
color: theme.primaryColor
}
}))
const SuperComponent = ({ classes, theme }) => (
<div className={classes.root}>
Red block
</div>
)
export default withStyles({ withTheme: true })(SuperComponent)
API
createUseStyles(styles, hookOptions)
- hook creatoruseStyles(hookOptions)
- hookcreateWithStyles(styles, decoratorOptions)
- decorator creatorwithStyles(decoratorOptions)
- decoratoruseTheme()
- hookwithTheme()
- decoratorhookOptions = { purgeUnused = true, ...jssSheetOptions }
decoratorOptions = { withTheme = false, ...hookOptions }
JssProvider
JssProvider
props
children
jss
- global jss by defaulttheme
- empty object by default