UNPKG

hcomp

Version:

HComp is a helper component library that aims to improve code readability and make your life easier.

26 lines (25 loc) 1.04 kB
import React from "react"; import { IForProps } from "../../shared/index.types"; /** * A component that iterates over an array of items and renders content for each item. * * When `items` is empty or not provided, it renders the `fallback` prop. * Otherwise, it maps over the `items` array, calling the `children` function for each item, * passing the item itself and its index as arguments. * * @example * ```tsx * <For items={users} fallback={<div>No users found.</div>}> * {(user, index) => ( * <div key={index}>{user.name}</div> * )} * </For> * ``` * * @param items - An array of items to iterate over. * @param fallback - The content to be displayed when `items` is empty or not provided. * @param children - A function that receives each item and its index, and returns the content to be rendered for that item. * @returns The rendered content based on the `items` prop. */ declare const For: <T>({ items, fallback, children }: IForProps<T>) => React.JSX.Element; export default For;