Skip to main content
Version: 4.0.0-rc.8

Styles

makeStyles

Imports

import { makeStyles } from '@rneui/themed';

Function Signture

makeStyles(styles: Styles | ((theme, props) => Styles))

If you want to keep your styles outside the component use makeStyles() (hook generator) to reference the theme and component props (optional param).

Usage

type Props = {
fullWidth?: boolean;
};

const useStyles = makeStyles((theme, props: Props) => ({
container: {
background: theme.colors.white,
width: props.fullWidth ? '100%' : 'auto',
},
text: {
color: theme.colors.primary,
},
}));

const MyComponent = (props: Props) => {
const styles = useStyles(props);

return (
<View style={styles.container}>
<Text style={styles.text}>Yo!</Text>
</View>
);
};

styled

Imports

import { styled } from '@rneui/themed';

Function Signture

styled(Component)<Props>(styles: Styles | ((theme, props) => Styles))

Usage

const Conatiner = styled(View)({
// default style of component
root: {
paddingHorizontal: 16,
},
});
const Surface = styled(View)((theme) => ({
// default style of component
root: {
backgroundColor: theme.colors.background,
},
}));

Using RNE's component

const RedButton = styled(Button)({
containerStyle: {
backgroundColor: 'red',
},
});

Using custom props

type MyCompProps = { bold?: boolean };

const Component = styled(Text)<MyCompProps>((theme, { bold }) => ({
root: {
fontWeight: bold ? 'bold' : 'normal',
color: theme.colors.primary,
},
}));