I have a state variable that holds the name of the theme (Light, Dark, etc).
In my render function, I would like to use the appropriate style for my components based on the theme.
If the DarkTheme
is being used on the "mainHeader" class for example, the style of the View component would be something like this:
<View style = {DarkTheme.mainHeader}>
</View>
If the theme is LightTheme, then it should be:
<View style = {LightTheme.mainHeader}>
</View>
For efficiency's sake, I thought that if I put the name of the theme in a state variable, I could do something like this:
<View style = {{this.state.theme + '.mainHeader'}}>
</View>
Expecting the evaluation of the theme variable to return either LightTheme.mainHeader or DarkTheme.mainHeader.
But I am wrong, this does not work. Is there anyway I can make this work?