createUnistylesComponent
Before reading this guide, make sure that you understand How Unistyles works and how Babel plugin manipulates your code.
Why do you need it?
- Unistyles cannot retrieve
ShadowNode
from third-party components because they might not expose a native view via the ref prop
- Another use case is when you use components that do not expect a
style
prop but require, for example, acolor
prop.
That’s why we created a way to subscribe such component to Unistyles updates.
Auto mapping for style
and contentContainerStyle
props
If your component expects the style
or contentContainerStyle
prop, Unistyles will automatically handle the mapping under the hood.
You just need to wrap your custom view in createUnistylesComponent
. We will also respect your style dependencies, so, for example, the Blurhash
component will only re-render when the theme changes.
Mapping custom props to Unistyles styles
If you need to ensure your component updates but it doesn’t use style
or contentContainerStyle
props, you can use mappings
:
TypeScript will autocomplete all your props, so there is no need to specify type manually.