I have progressbar in my project which takes in a range of values and i have added validation according to that. it is working but seems a lot of repetition. Need a better solution. Here is the code :-
const ProgressBar = ({ price }) => {
return (
<div className="bar">
{price === 1 && (
<React.Fragment>
<span className="percentage one" />
<span className="percentage two" />
</React.Fragment>
)}
{price === 2 && (
<React.Fragment>
<span className="percentage one" />
<span className="percentage two" />
<span className="percentage three" />
</React.Fragment>
)}
{price === 3 && (
<React.Fragment>
<span className="percentage one" />
<span className="percentage two" />
<span className="percentage three" />
<span className="percentage four" />
</React.Fragment>
)}
</div>
);
};
So the price above can be 1,2,3 or 4 and I am making checks according to the number and then rendering a range of spans with the classes one, two, three, four. If a number is 2 then it will render 2 spans with class one and two. Can someone suggest a better solution?