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
}
each
: A boolean value to determine whether to render the children or the fallback.fallback
: A ReactNode to render wheneach
is falsey.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.