From 507ab2fef63dca79eaaf77ea911cc48b0179f67a Mon Sep 17 00:00:00 2001 From: soham2k06 Date: Mon, 15 Jan 2024 13:48:19 +0530 Subject: [PATCH] fix: post can't be updated without input change --- components/editor.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/editor.tsx b/components/editor.tsx index 21f2bb6..445f25f 100644 --- a/components/editor.tsx +++ b/components/editor.tsx @@ -24,7 +24,7 @@ interface EditorProps { type FormData = z.infer export function Editor({ post }: EditorProps) { - const { register, handleSubmit } = useForm({ + const { register, handleSubmit, formState } = useForm({ resolver: zodResolver(postPatchSchema), }) const ref = React.useRef() @@ -84,6 +84,8 @@ export function Editor({ post }: EditorProps) { }, [isMounted, initializeEditor]) async function onSubmit(data: FormData) { + if (!formState.isDirty) return + setIsSaving(true) const blocks = await ref.current?.save() @@ -140,7 +142,7 @@ export function Editor({ post }: EditorProps) {