UNPKG

1.71 kBTypeScriptView Raw
1import { KeyGenerator } from './useCompound';
2export interface UseCompoundItemReturnValue<Key> {
3 /**
4 * The unique key for the child component.
5 * If the id was provided to `useCompoundItem`, this will be the same value.
6 * Otherwise, this will be a value generated by the `missingKeyGenerator`.
7 */
8 id: Key | undefined;
9 /**
10 * The 0-based index of the child component in the parent component's list of registered children.
11 */
12 index: number;
13 /**
14 * The total number of child components registered with the parent component.
15 * This value will be correct after the effect phase of the component (as children are registered with the parent during the effect phase).
16 */
17 totalItemCount: number;
18}
19/**
20 * Registers a child component with the parent component.
21 *
22 * @param id A unique key for the child component. If the `id` is `undefined`, the registration logic will not run (this can sometimes be the case during SSR).
23 * @param itemMetadata Arbitrary metadata to pass to the parent component. This should be a stable reference (e.g. a memoized object), to avoid unnecessary re-registrations.
24 * @param missingKeyGenerator A function that generates a unique id for the item.
25 * It is called with the set of the ids of all the items that have already been registered.
26 * Return `existingKeys.size` if you want to use the index of the new item as the id.
27 *
28 * @ignore - internal hook.
29 */
30export declare function useCompoundItem<Key, Subitem>(id: Key | KeyGenerator<Key>, itemMetadata: Subitem): UseCompoundItemReturnValue<Key>;
31export declare function useCompoundItem<Key, Subitem>(id: Key, itemMetadata: Subitem): UseCompoundItemReturnValue<Key>;