2
0

🐛 Fix bug when removing first message from create chat comp a…

Closes #1457
This commit is contained in:
Baptiste Arnaud
2024-04-23 11:39:10 +02:00
parent c75148c800
commit bc50d62cf6

View File

@ -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)
@ -183,3 +184,9 @@ export const TableList = <T,>({
</Stack>
)
}
const addIdsIfMissing = <T,>(items?: T[]): ItemWithId<T>[] | undefined =>
items?.map((item) => ({
id: createId(),
...item,
}))