J
J
JordanBelford2021-05-08 12:12:30
Frontend
JordanBelford, 2021-05-08 12:12:30

How to draw a component in a loop?

Hello everyone, you need to draw a specific number of times the component for this wrote the following function:

const renderPageNumber = (number) => {
        for (let i = 1; i <= number; i++) {
            <NextIcon i={i} />
        }
    }

but the problem is that this function returns void, I can't write return before the component. How can this problem be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VladimirAsmo, 2021-05-08
@JordanBelford

If you really need it, you can do something like this:

const renderPageNumber = (number) => {
    const nextIcons = Array(number)
      .map((icon, id) => <NextIcon i={id + 1} key={?} />);
    return nextIcons;
  }

But damn it, what a perversion to pass the number of child components to the component and draw them in a loop. Re-read the textbook, you somehow didn’t start your acquaintance with this library quite correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question