diff --git a/client/components/new-post/drag-and-drop/index.tsx b/client/components/new-post/drag-and-drop/index.tsx index 08973db7..dfae57ce 100644 --- a/client/components/new-post/drag-and-drop/index.tsx +++ b/client/components/new-post/drag-and-drop/index.tsx @@ -1,5 +1,5 @@ import { Button, Text, useTheme, useToasts } from '@geist-ui/core' -import { useCallback, useEffect } from 'react' +import { memo, useCallback, useEffect } from 'react' import { useDropzone } from 'react-dropzone' import styles from './drag-and-drop.module.css' import { Document } from '../' @@ -170,4 +170,4 @@ function FileDropzone({ setDocs }: { setDocs: ((docs: Document[]) => void) }) { ) } -export default FileDropzone \ No newline at end of file +export default memo(FileDropzone) \ No newline at end of file diff --git a/client/components/new-post/index.tsx b/client/components/new-post/index.tsx index 6e41a42f..373c62f3 100644 --- a/client/components/new-post/index.tsx +++ b/client/components/new-post/index.tsx @@ -24,6 +24,7 @@ const Post = () => { content: '', id: generateUUID() }]) + const [isSubmitting, setSubmitting] = useState(false) const remove = (id: string) => { @@ -63,11 +64,10 @@ const Post = () => { setDocs(docs.map((doc) => doc.id === id ? { ...doc, content } : doc)) }, [docs]) - const uploadDocs = (files: Document[]) => { + const uploadDocs = useCallback((files: Document[]) => { // if no title is set and the only document is empty, const isFirstDocEmpty = docs.length === 1 && docs[0].title === '' && docs[0].content === '' const shouldSetTitle = !title && isFirstDocEmpty - console.log(shouldSetTitle, title, isFirstDocEmpty) if (shouldSetTitle) { if (files.length === 1) { setTitle(files[0].title) @@ -78,15 +78,15 @@ const Post = () => { if (isFirstDocEmpty) setDocs(files) else setDocs([...docs, ...files]) - } + }, [docs, title]) + return (