0

I am trying react-bootstrap.

I want to paginate like that with the component Pagination here .

My code is :

<Pagination size="sm">
  <Pagination.First />
  <Pagination.Prev />
     { () => {for(let page=1;page<meta.last_page;page++){
        return <Pagination.Item>{page}</Pagination.Item>
     }}}
  <Pagination.Next />
  <Pagination.Last />
</Pagination>

I have this error :

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of from render

How to loop to display the component Pagination ?

1 Answer 1

1

Just by looking at your syntax. you can't use a function to display an element. Basically all elements needs to be displayed directly without that outter () =>

  {items.map((item) => {
    return ...
  })}

Use this to replace your piece. Sometimes you might want to add a container to it, such as Fragment.

  <>
    ... // list of items
  </>
Sign up to request clarification or add additional context in comments.

2 Comments

ok thanks for the explanation. But in the case of a loop "for". How to write this ?
essentially we are doing a loop, but for is not good here, since you need an array of items back. So if you need a for, you need to create an array object first. ex. let a = [] and then go add item via a.push(item) and so forth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.