I have a similar question to this question
I am trying to convert create a custom components where it convert each string to difference color for example
input "A B C D"
output A B C D (cant chance color in this question, so I used Bolt and emphasis instead, same logic)
Currently I have
//In component
function MakeColor(){
var input = [
{letter:"A",color:"Red"},
{letter:"B",color:"Blue"},
{letter:"C",color:"Orange"},
{letter:"D",color:"Yellow"}
];
var output ="";
input.forEach(function(object){
output=output+"<span className="+object.color+">"+object.letter+"</span>";
})
return React.createElement('div',null,output)
}
//In another component
class Display extends Component {
componentDidMount(){
this.setState({letter:MakeColor();})
}
render(){
<div>{this.state.letter}</div>
}
}
//In the outer component
...
render(){
return(
...
<Display />
...
)
}
...
This will return the text
<span className=Red>A</span><span className=Blue>B</span><span className=Orange>C</span><span className=Yellow>D</span> instead of ABCD
output.push(...)push the value in each iteration instead of appending