I'm building my own invoice/estimate generator with React.
I want to have a number of lines "product" equivalent to my state.
I wanted to do a loop
and return
my JSX
. But I have no error, but my line product appears once only, and my state is set to 2
.
Here is my try :
export default function ProductInformations(props: TProductInformations) {
const [numberOfProducts, setNumberOfProducts] = useState<number>(2);
const handleNumberOfProducts = (type: string) => {
if (type === "add") return setNumberOfProducts(numberOfProducts + 1);
if (type === "remove") return setNumberOfProducts(numberOfProducts - 1);
};
for (let i = 0; i <= numberOfProducts; i++) {
return (
// here is <p> with "price", "quantity", "name of the product"...
);
}
}
As the JSX is a bit long, I don't want to do a function that returns html and call the function in JSX.
Any idea why ?