Что наиболее эффективно (и почему)?
"Каскадные" стили:
export function Title({ children, small }) {
return <Text style={[styles.title, small && styles.small]}>{children}</Text>;
}
const styles = StyleSheet.create({
title: {
fontFamily: "Roboto",
fontWeight: "500",
fontSize: 20
},
small: {
fontSize: 14
}
});
Или уникальный стиль:
export function Title({ children, small }) {
return (
<Text style={small ? styles.titleSmall : styles.title}>{children}</Text>
);
}
const title = {
fontFamily: theme.fontFamily,
fontWeight: "500"
};
const styles = StyleSheet.create({
title: {
...title,
fontSize: 20
},
titleSmall: {
...title,
fontSize: 14
}
});
Примечание для себя: http://wiki.c2.com/?PrematureOptimization