Skip to main content

For

Used to render elements from a list and optionally show a fallback when the list is empty.

Anatomy

This component is a utility and does not render any DOM elements.

Import

import { For, type ForProps } from '@pluralsight/react'

Usage

Basic

Result
Loading...
Live Editor

Displaying a fallback

To display a fallback when the list is empty, use the fallback prop.

Result
Loading...
Live Editor

Behavior

There are no behaviors associated with this component.

API

Parameters

export interface ForProps<T, U extends JSX.Element> {
each: readonly T[]
fallback?: NonNullable<ReactNode> | null
children: (item: T, index: number) => U
}
  1. each: A boolean value to determine whether to render the children or the fallback.
  2. fallback: A ReactNode to render when each is falsey.
  3. children: A function that returns a JSX.Element to render for each item in the list via a map callback.

Accessibility

There is no special accessibility considerations for this component.