From b82f04ea04d366092b39d18683b3ca758ddfac2c Mon Sep 17 00:00:00 2001 From: Henit Chobisa Date: Fri, 8 Dec 2023 16:34:17 +0530 Subject: [PATCH] fix: document editor debounced --- .../projects/[projectId]/pages/[pageId].tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx index b678e951a..3d416c507 100644 --- a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx +++ b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState, ReactElement } from "react"; +import React, { useEffect, useRef, useState, ReactElement, useCallback } from "react"; import { useRouter } from "next/router"; import useSWR, { MutatorOptions } from "swr"; import { Controller, useForm } from "react-hook-form"; @@ -59,7 +59,7 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { const { user } = useUser(); - const { handleSubmit, reset, setValue, watch, getValues, control } = useForm({ + const { handleSubmit, setValue, watch, getValues, control } = useForm({ defaultValues: { name: "", description_html: "" }, }); @@ -328,9 +328,12 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { description_html: "", }); - const debouncedFormSave = debounce(async () => { - handleSubmit(updatePage)().finally(() => setIsSubmitting("submitted")); - }, 1500); + const debouncedFormSave = useCallback( + debounce(async () => { + handleSubmit(updatePage)().finally(() => setIsSubmitting("submitted")); + }, 1500), + [handleSubmit] + ); if (error) return (