From 07cb9494f50b8bf40bdb552696f3f6eb26148bd9 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Sun, 12 Jun 2022 20:28:13 +0300 Subject: [PATCH] fix: unregister field for lesson form --- src/components/Forms/LessonForm/LessonForm.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/Forms/LessonForm/LessonForm.tsx b/src/components/Forms/LessonForm/LessonForm.tsx index 669a687..36e7dd5 100644 --- a/src/components/Forms/LessonForm/LessonForm.tsx +++ b/src/components/Forms/LessonForm/LessonForm.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { FormControl, FormHelperText, @@ -52,12 +52,19 @@ const LessonForm: React.FC = ({ register, watch, formState: { errors, isDirty }, + unregister, } = reactHookForm; const [isLinkedVideoUrl, setIsLinkedVideoUrl] = useState(false); const watchDescription = watch('description'); + useEffect(() => { + if (!isLinkedVideoUrl) { + unregister('linked_video_url'); + } + }, [isLinkedVideoUrl]); + return (