score:0

Accepted answer

how can i apply the color based on the based string? let say this.props.company name is the base string,right? if its so then you can do something like this

style={{ backgroundcolor: backgroundmapping[this.props.company], color: colormapping[this.props.company] }}

but,wait

is this the right approach, could i just use 1 mapping object? no,then why?what if there is no color for given this.props.company? so you code may need to check first that for given company name mapping found,and of course you should use single mapping instead of two, then how? consider the steps create a theme object like this

const theme={
       facebook:{color:"while",background:"blue"},
       defaulttheme:{
            color:"while",background:"black"
        }
 }

and then you can assign this theme to your component as following

 <div style={theme[this.props.company]||theme.default}>
   {props.company} //facebook
   </div>

Related Query

More Query from same tag