Skip to content

Commit

Permalink
🐛 Fix bug when removing first message from create chat comp a…
Browse files Browse the repository at this point in the history
Closes #1457
  • Loading branch information
baptisteArno committed Apr 23, 2024
1 parent c75148c commit bc50d62
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/builder/src/components/TableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const TableList = <T,>({
onItemsChange,
}: Props<T>) => {
const [items, setItems] = useState(
initialItems ?? (hasDefaultItem ? ([defaultItem] as ItemWithId<T>[]) : [])
addIdsIfMissing(initialItems) ??
(hasDefaultItem ? ([defaultItem] as ItemWithId<T>[]) : [])
)
const [showDeleteIndex, setShowDeleteIndex] = useState<number | null>(null)

Expand Down Expand Up @@ -183,3 +184,9 @@ export const TableList = <T,>({
</Stack>
)
}

const addIdsIfMissing = <T,>(items?: T[]): ItemWithId<T>[] | undefined =>
items?.map((item) => ({
id: createId(),
...item,
}))

0 comments on commit bc50d62

Please sign in to comment.