fix: unregister field for lesson form

This commit is contained in:
Sergey Yarkov 2022-06-12 20:28:13 +03:00
parent 1b865c6df7
commit 07cb9494f5

View File

@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { import {
FormControl, FormControl,
FormHelperText, FormHelperText,
@ -52,12 +52,19 @@ const LessonForm: React.FC<LessonFormPropsType> = ({
register, register,
watch, watch,
formState: { errors, isDirty }, formState: { errors, isDirty },
unregister,
} = reactHookForm; } = reactHookForm;
const [isLinkedVideoUrl, setIsLinkedVideoUrl] = useState<boolean>(false); const [isLinkedVideoUrl, setIsLinkedVideoUrl] = useState<boolean>(false);
const watchDescription = watch('description'); const watchDescription = watch('description');
useEffect(() => {
if (!isLinkedVideoUrl) {
unregister('linked_video_url');
}
}, [isLinkedVideoUrl]);
return ( return (
<form onSubmit={onSubmit}> <form onSubmit={onSubmit}>
<Stack spacing={'5'}> <Stack spacing={'5'}>