UNPKG

@assistant-ui/react

Version:

TypeScript/React library for AI Chat

36 lines 1.71 kB
"use client"; import { jsx as _jsx } from "react/jsx-runtime"; import { memo, useMemo } from "react"; import { ThreadListItemByIndexProvider, useAssistantState, } from "../../context/index.js"; /** * Renders a single thread list item at the specified index. * * This component provides direct access to render a specific thread * from the thread list using the provided component configuration. * * @example * ```tsx * <ThreadListPrimitive.ItemByIndex * index={0} * components={{ * ThreadListItem: MyThreadListItem * }} * /> * ``` */ export const ThreadListPrimitiveItemByIndex = memo(({ index, archived = false, components }) => { const ThreadListItemComponent = components.ThreadListItem; return (_jsx(ThreadListItemByIndexProvider, { index: index, archived: archived, children: _jsx(ThreadListItemComponent, {}) })); }, (prev, next) => prev.index === next.index && prev.archived === next.archived && prev.components.ThreadListItem === next.components.ThreadListItem); ThreadListPrimitiveItemByIndex.displayName = "ThreadListPrimitive.ItemByIndex"; export const ThreadListPrimitiveItems = ({ archived = false, components, }) => { const contentLength = useAssistantState(({ threads }) => archived ? threads.archivedThreadIds.length : threads.threadIds.length); const listElements = useMemo(() => { return Array.from({ length: contentLength }, (_, index) => (_jsx(ThreadListPrimitiveItemByIndex, { index: index, archived: archived, components: components }, index))); }, [contentLength, archived, components]); return listElements; }; ThreadListPrimitiveItems.displayName = "ThreadListPrimitive.Items"; //# sourceMappingURL=ThreadListItems.js.map