trying to change string variable from React.Children.map
, then React.cloneElement
to change the color. I have a Title on my homepage. I want to update node color of each character within the title string. Trying to do it this way, but getting en error of : Cannot read property 'colorString' of undefined
const LetterStyle = React.createClass({
colorString: function(value){
this.setState({color: "green"});
},
render: function(){
const colorArray = []
var childrentWithProps = React.Children.forEach(this.props.children, (child, i) => {
for (var i=0; i<child.length; i++){
return React.Children.map(child[i], function(content, i) {
if(content !== " "){
React.cloneElement(content, { colorString: this.colorString })
}
});
}
})
return(
<h1 className="lead" ref="lead">
<span>{childrentWithProps}</span>
</h1>
);
}
});