Skip to Content
ComponentsFor

For

For is a small rendering utility component for list output, loading states, empty states, and wrapper composition.

Live Example

List rendering with loading and empty states

This demo uses the actual `For` component and lets you toggle loading and empty states without leaving the page.

Keyboard

In stock

Trackpad

Backorder

Monitor arm

In stock

Import

import { For } from "react-rsc-kit";

Props

PropTypeDefaultDescription
eachT[]requiredArray to render.
children(item: T, index: number, array: T[]) => ReactNoderequiredRender function for each item.
getKey(item: T, index: number) => string | numberundefinedStable key extractor.
empty() => ReactNodeundefinedRender function used when the array is empty.
loading() => ReactNodeundefinedRender function used when loading.
isLoadingbooleanfalseEnables the loading branch.
asElementTypeundefinedWrapper element or component.
wrapperPropsOmit<ComponentProps<E>, "children">{}Props passed to the wrapper.

Usage

import { For } from "react-rsc-kit"; function ProductList({ products, isLoading, }: { products: { id: string; name: string }[]; isLoading: boolean; }) { return ( <For each={products} isLoading={isLoading} getKey={(product) => product.id} loading={() => <p>Loading products...</p>} empty={() => <p>No products found.</p>} as="ul" > {(product) => <li>{product.name}</li>} </For> ); }

Notes

  • Provide getKey when the list has stable item identifiers.
  • Use as when you need a wrapper element like ul, ol, or section.
  • This component is available from the server-safe entrypoint.
Last updated on