State Based Styles
This includes the ability to define styles based on the component's state. This allows you to create dynamic and interactive styles that change based on user interactions or other events.
The extended component accept a states prop, which is an object containing the state of the component. This prop can contain any number of state keys and values, for example {hover: true, active: true}. The library then uses this prop to apply the corresponding state styles to the component.
The states prop allows developers to easily control the state of the component and its styles. For example, it can be used to apply hover styles to a button when the mouse is over the button, or to apply active styles to a button when it is clicked. The library utilizes the states prop to look up the state styles in the global style map and apply them to the component.
It is important to note that the states prop is optional and will be used only if passed, otherwise the component will use the default styles.
Here is an example of using the states prop can be used:
const StyledButton = styled(Pressable, {
const StyledButtonText = styled(Text, {
const [isHovered, setIsHovered] = useState(false)
const [isActive, setIsActive] = useState(false)
<Provider config={config}>
states={{ hover: isHovered, active: isActive }}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onMouseDown={() => setIsActive(true)}
onMouseUp={() => setIsActive(false)}
<StyledButtonText>Click Me</StyledButtonText>
In the example above, we create a functional Button component that wraps a StyledButton component, which is the component returned by the styled function. The Button component uses useState hooks to track whether the button is currently being hovered over or pressed (active). It then passes the current state to the StyledButton component via the states prop.
When the button is hovered over, the isHovered state is set to true, which causes the StyledButton component to apply the hover styles to itself. When the button is pressed, the isActive state is set to true, which causes the StyledButton component to apply the active styles to itself.
This allows the developer to easily control the component's state and styles using the states prop.
Supported States
State Specificity Map
State specificity
State props are resolved based on the above state precedence
For instance, if we pass both hover style and invalid style to a component, the hover style will be applied to the component.
Nested specificity
Nested declared state props are more specific