Skip to content

<ReactListItems>

This is a wrapper component to render the list of items returned by <ReactList>. It provides multiple ways to render your items and handles the looping logic for you.

Behavior

The component will return null (render nothing) in the following cases:

  • During initial loading (initialLoading is true)
  • When there are no items (items.length === 0)
  • When there is an error

Props

NameTypeDescription
renderItemFunctionOptional. A function that receives { item, index } and returns a React element for each item
childrenFunctionOptional. A function that receives the scope object with { items, setSort, sort }

Rendering Options

Using renderItem prop

The renderItem prop is a function that gets called for each item in the list. It receives the item and its index.

jsx
<ReactList endpoint="users" perPage={10}>
  <ReactListItems
    renderItem={({ item, index }) => (
      <div key={item.id}>
        <h3>{item.name}</h3>
        <p>Index: {index}</p>
      </div>
    )}
  />
</ReactList>

renderItem Parameters

NameTypeDescription
itemObjectAn individual item from the set of items returned by the API
indexNumberThe index of the item. It will always start from 0 for any page

Using children as function

When using children as a function, you get access to the entire items array and can handle the looping yourself. This gives you more control over the rendering.

jsx
<ReactList endpoint="users" perPage={10}>
  <ReactListItems>
    {({ items, setSort, sort }) => (
      <div>
        {items.map((item) => (
          <div key={item.id}>
            <h3>{item.name}</h3>
            <p>{item.email}</p>
          </div>
        ))}
      </div>
    )}
  </ReactListItems>
</ReactList>

children callback Props

NameTypeDescription
itemsArrayThe array of items returned by the API
setSortFunctionFunction to update sorting. Call with `{ by: 'fieldName', order: 'asc'
sortObjectCurrent sort state with `{ sortBy: string, sortOrder: 'asc'

Default behavior

If neither renderItem nor children are provided, the component will render each item as a formatted JSON string inside a <pre> tag.

jsx
<ReactListItems />
// Renders: <pre>{JSON.stringify(item, null, 2)}</pre> for each item