I would like to pass props noOfIcons to my ChartLegend component and if there is noOfIcons value then I would like to render the given number of icons. So if noOfIcons = 2 then render 2 <Icon/>. I've tried the following but it always renders only 1 <Icon/>, What am I missing? & if there is a simple way to handle this please suggest. Many thanks.
<ChartLegend iconName={"square-full"} noOfIcons={2} label={'label'} />
const ChartLegend = props => {
const { iconName, label, noOfIcons = 2 } = props;
const renderIcons = () => {
if (!noOfIcons) {
return <Icon
name={iconName}
type='solid'
/>;
}
else {
for (let i = 0; i < noOfIcons; i++) {
return <Icon
name={iconName}
type='solid'
/>;
}
}
};
return (
<Col>
{renderIcons()}
{label}
</Col>
);
};
export default ChartLegend;