BearCola
4/26/2019 - 10:03 PM

Array Length 만큼 rendering 하기

import React, { Component } from "react";
import Box from "./Box";

export default class BoxContainer extends Component {
  static defaultProps = {
    numBoxes: 18,
    allColors: [
      "purple",
      "magenta",
      "violet",
      "pink",
      "orange",
      "blue",
      "yellow"
    ]
  };
  render() {
    const boxes = Array.from({ length: this.props.numBoxes }).map(() => (
      <Box color={this.props.allColors} />
    ));
    return <div className="BoxContainer">{boxes}</div>;
  }
}