CoastalCommitsPastes/client/components/edit-document-list/index.tsx

45 lines
982 B
TypeScript
Raw Normal View History

import type { Document } from "@lib/types"
import DocumentComponent from "@components/edit-document"
import { ChangeEvent, memo, useCallback } from "react"
2022-04-09 20:48:19 -04:00
const DocumentList = ({
docs,
removeDoc,
updateDocContent,
updateDocTitle,
onPaste
}: {
docs: Document[]
updateDocTitle: (i: number) => (title: string) => void
updateDocContent: (i: number) => (content: string) => void
removeDoc: (i: number) => () => void
onPaste: (e: any) => void
}) => {
2022-04-09 20:48:19 -04:00
const handleOnChange = useCallback(
2022-04-09 20:54:08 -04:00
(i: number) => (e: ChangeEvent<HTMLTextAreaElement>) => {
2022-04-09 20:48:19 -04:00
updateDocContent(i)(e.target.value)
},
[updateDocContent]
)
2022-04-09 20:48:19 -04:00
return (
<>
{docs.map(({ content, id, title }, i) => {
return (
<DocumentComponent
onPaste={onPaste}
key={id}
remove={removeDoc(i)}
setTitle={updateDocTitle(i)}
handleOnContentChange={handleOnChange(i)}
content={content}
title={title}
/>
)
})}
</>
)
}
export default memo(DocumentList)