I have button themes called green,blue and red .my solution works but it looks messy. how can I use them like in objects instead if arguments
const buttonBG = theme === 'green' ? COLORS.green : theme === "blue" ? COLORS.blue : ""
const fontTheme = theme === 'green' ? FONTS.green : theme === "blue" ? FONTS.blue : ""
const styles = StyleSheet.create({
button: {
backgroundColor: buttonBG,
borderRadius: 12,
paddingVertical: 16,
paddingHorizontal: 20,
lineHeight: 24,
font: fontTheme
},
2
Answers
I imagine you pick the color of the theme inside the
<ThemedBtn/>
, perhaps doing it outside the component will make the code inside<ThemedBtn/>
look cleaner?App Component
ThemeBtn Component
One cleaner way is to pass values in styles as follows: