Skip to main content
The For component provides a declarative way to render lists and arrays in React, with automatic empty state handling and support for numeric ranges.

When to Use

  • Render lists of items from arrays
  • Generate repeated elements from a count
  • Display fallback UI when lists are empty
  • Avoid manual .map() calls with cleaner syntax
  • Render list containers with semantic HTML

Basic Usage

Component API

For

Renders items without a wrapper element.
TArray | number
required
Array to iterate over, or a number to generate a range [0…n-1]
(item: T, index: number, array: T[]) => React.ReactNode
Render function called for each item. Receives item, index, and full array
(item: T, index: number, array: T[]) => React.ReactNode
Alternative to children prop for rendering items
React.ReactNode
Content to display when the array is empty or count is 0

ForWithWrapper

Renders items inside a container element.
React.ElementType
default:"ul"
Container element type
boolean
default:"false"
Whether to show fallback instead of empty container when list is empty
HTMLAttributes
All other props for the container element (className, style, etc.)

Examples

List with Fallback

Numeric Range for Skeletons

With Container Element

Accessing Index and Array

Semantic List Wrapper

Comparison to Native Patterns

Traditional Map

With For Component

Common Use Cases

Dynamic Grid Layout

Table Rows

When using numeric ranges with each={n}, the component generates an array [0, 1, 2, ..., n-1] and passes each number as the item.
The For component automatically checks for empty arrays, null/undefined values, and zero counts before rendering the fallback.