If you find that Unistyles lacks certain features, you can easily extend its functionality with plugins.
Plugins are functions that accept a style object and return a new style object.
They are resolved in the order in which they were passed to the addConfig function in UnistylesRegistry.
Create a plugin
To create a plugin, you need to import the UnistylesPlugin type:
Then, create a function that conforms to this type:
Your plugin must have a unique name; otherwise, it will be rejected from the registry.
onParsedStyle
The onParsedStyle function is called for every style object in the stylesheet passed to the useStyles hook.
These objects are processed after Unistyles has finished parsing them, so they do not include:
variants
breakpoints
theme
media queries
For example:
You will get, for instance, the following calls:
Your function will be called twice: once for the container and once for text styles.