const NUM_BOXES = 32;
class Boxes extends Component {
constructor(props) {
super(props);
const boxes = Array(NUM_BOXES).fill()
.map(this.getRandomColor, this);
this.state = {boxes};
this.intervalId = setInterval(() => {
const boxes = this.state.boxes.slice();
const ind = Math.floor(Math.random()*boxes.length);
boxes[ind] = this.getRandomColor();
this.setState({boxes});
}, 300);
}
componentWillUnmount() {
clearInterval(this.intervalId);
}
}