I have a react component which renders a 10-punch punchcard. It receives a "punched" prop to determine how many of the punches should be filled in. My current code works as expected, but I would appreciate help finding a more elegant solution.
const punches = () => {
const arr = [];
let numpunch = 0;
let i;
for (i = 0; i < 10; i++) {
if (numpunch !== punched) {
arr.push(<PunchFill key={i} />);
numpunch++;
} else {
arr.push(<Punch key={i} />);
}
}
return arr;
};
The built-in array methods don't really seem to fit my need as far as I can see as that would require first setting up an array of the right size and also create a new problem of how to keep track of the number of FilledPunches already present.