Не пойму как вызвать метод generateArray
из метода quadroData
в компоненте. Код ниже не вызывает generateArray
(пример в codepen)
class Quadro extends React.Component {
constructor(props) {
super(props);
this.state = {
data: this.quadroData(props.width)
}
}
getColor(colors = ["red", "yellow"]) {
return colors[Math.floor(Math.random() * colors.length)];
}
generateArray(width, pos) {
console.log('here')
return [...new Array(width)].map((item, index) => ({
y: pos,
x: index,
color: this.getColor()
}));
}
quadroData(width) {
return [...new Array(width)].map((item, index) =>
this.generateArray(width, index)
)
}
render() {
return (<div>
{this.state.data.map((index) => <div>1</div>)}
</div>)
}
};