Reputation: 1
NOTE: Its App.js component
I have a State
state = {
contacts: [...data is coming from an api],
bgColors: ["bg-red","bg-blue",...so On]
// bg colors array consist of class coming from css
}
inside render function->
I Used this.state.contacts.map
to display data from contacts(state)
inside map function there is a div with className
<div className={`col-sm-3 relative book ${Here I want to display bgColors String one by one} `}>
Upvotes: 0
Views: 37
Reputation: 17350
Just use the native Array.join
method to generate a string of classes:
<div className={`col-sm-3 relative book ${this.state.bgColors.join(' ')} `} />
Upvotes: 1