import * as React from 'react'; import React__default from 'react'; /** * Symbol marker to indicate that the item itself should be used as the key. * Use this for primitive arrays (string[], number[]) where each item is its own unique identifier. * * @example * ```tsx * import ReactList, { SELF } from 'react-list'; * * * ``` */ declare const SELF: unique symbol; /** * Symbol marker to indicate that the array index should be used as the key. * Use this when items have no stable unique identifier and the list is static * (not reordered, inserted, or filtered). * * @example * ```tsx * import ReactList, { INDEX } from 'react-list'; * * * ``` */ declare const INDEX: unique symbol; /** * The type of React key value. * @internal */ type Key = string | number; /** * Represents a slot that can be either a component, a React node, or a component with default props. * * @typeParam P - The props type that the slot component accepts. * * @example * ```tsx * // Using a component directly * const slot: Slot<{ name: string }> = MyComponent; * * // Using a React node directly * const slotNode: Slot<{ name: string }> =
Hello
; * * // Using a component with default props * const slotWithProps: Slot<{ name: string }> = { * component: MyComponent, * props: { name: 'Default' } * }; * ``` */ type Slot

= React__default.ComponentType

| React__default.ReactNode | { /** * The component to render. * Accepts P plus any additional custom props supplied via `props`. * Uses `any` because the component may require extra props * that are provided at runtime via the `props` field. */ component: React__default.ComponentType; /** * Extra props to merge with the standard slot props. * These are passed to the component alongside the default slot props. */ props?: Record; }; /** * The context object passed to item-related callbacks (slot props and keyExtractor functions). * * @typeParam T - The type of items in the data array. */ type ItemContext = { /** The current data item. */ item: T; /** The index of the current item in the data array. */ index: number; /** The complete data array. */ data: T[]; }; /** * Extracts a unique key or value from a data item. * * Can be specified as: * - `SELF` — use the item itself as the key (for primitive arrays) * - `INDEX` — use the array index as the key * - A key of the item type (`keyof T`) * - A dot-separated path to a nested property (e.g., `'user.address.city'`) * - A function that receives an {@link ItemContext} object * * @typeParam T - The type of items in the data array. */ type KeyExtractor = typeof SELF | typeof INDEX | keyof T | string | ((ctx: ItemContext) => Key); /** * Props for the {@link ReactList} component. * * @typeParam T - The type of items in the data array. */ interface ReactListProps { /** * The array of data items to render. */ data: T[]; /** * Extracts a unique key for each item in the list. * * Can be specified as: * - `SELF` — use the item itself as the key (for primitive arrays like `string[]` or `number[]`) * - `INDEX` — use the array index as the key * - A key of the item type (`keyof T`) * - A dot-separated path to a nested property (e.g., `'user.address.city'`) * - A function that receives the item and index, returning a string or number * * @example * ```tsx * import ReactList, { SELF } from 'react-list'; * * // Using SELF for primitive arrays * * * // Using a key path * * * // Using a dot path for nested properties * * * // Using a function * item.id} * {...props} * /> * ``` */ keyExtractor?: KeyExtractor; /** * Slot configuration for rendering different list states. */ slots: { /** * Slot for rendering each item in the list. * Receives the current item, its index, and the full data array. */ item: Slot>; /** * Optional slot for rendering the empty state. * Receives the (empty) data array. */ empty?: Slot<{ /** The (empty) data array. */ data: T[]; }>; }; } /** * Type guard to check if a value is a slot configuration object with component and props. * * @param value - The value to check. * @returns `true` if the value is a slot configuration object. */ declare function isSlotConfig(value: any): value is { component: React__default.ComponentType; props?: Record; }; /** * Renders a slot by creating a React element from the slot definition. * * Uses a stable `SlotBridge` wrapper for function/component slots so that: * 1. Hooks inside slot components get their own proper React context * 2. The bridge identity is stable across renders, avoiding unnecessary remounts * * @template P - The props type for the slot component. * @param slot - The slot definition to render. * @param props - The props to pass to the slot component. * @param key - Optional React key to add to the element. * @returns A React node, or `null` if no slot is provided. */ declare function renderSlot

(slot: Slot

| undefined, props: P, key?: Key): React__default.ReactNode; /** * Extracts a unique key for a list item using the provided key extractor. * * @template T - The type of the data item. * @param item - The data item. * @param index - The index of the item in the array. * @param data - The complete data array. * @param keyExtractor - The key extractor: `SELF`, `INDEX`, a property key, a dot path, or a function. * @returns A unique key (string or number) for the item. * * @example * ```tsx * getKey({ id: 1, name: 'Item' }, 0, [], 'id'); // => 1 * getKey({ id: 1, name: 'Item' }, 0, [], ({ item }) => item.id); // => 1 * getKey({ name: 'Item' }, 0, [], 'id'); // => 0 (fallback to index) * getKey('apple', 0, [], SELF); // => 'apple' * getKey('apple', 0, [], INDEX); // => 0 * getKey({ user: { id: 1 } }, 0, [], 'user.id'); // => 1 * ``` */ declare function getKey(item: T, index: number, data: T[], keyExtractor: KeyExtractor): Key; declare function ReactList({ data, keyExtractor, slots, }: ReactListProps): React.ReactNode; export { INDEX, type ItemContext, type KeyExtractor, ReactList, type ReactListProps, SELF, type Slot, ReactList as default, getKey, isSlotConfig, renderSlot };