Create components with dynamic style props
mainThe styled utility accepts a second argument: a style resolver function. This function allows you to return styles based on props passed to the component. These are referred to as style props.
Accessing Style Props
Use the first parameter of the style resolver function to access style props. A proxy is used to differentiate these from standard component props.
Accessing Component Props
Use the second parameter of the style resolver function to access standard component props that are not intended for styling (e.g., disabled, onClick).
import { styled } from 'restyle'
interface ButtonStyleProps {
backgroundColor: string
color: string
}
// styleProps contains the style-specific props
// props contains the rest of the component's props
const Button = styled('button', (styleProps: ButtonStyleProps, props) => ({
backgroundColor: styleProps.backgroundColor,
color: styleProps.color,
opacity: props.disabled ? 0.6 : 1,
}))import { styled } from 'restyle'
interface ButtonStyleProps {
backgroundColor: string
color: string
}
const Button = styled('button', (styleProps: ButtonStyleProps, props) => ({
backgroundColor: styleProps.backgroundColor,
color: styleProps.color,
opacity: props.disabled ? 0.6 : 1,
}))