import React, { useEffect } from 'react'; import { Controller, useFormContext } from 'react-hook-form'; import FormHelperText from '@mui/material/FormHelperText'; import { Editor } from './editor'; import { IRHFEditorProps } from '../types'; /** * @description {RHFEditor} - Renders a Rich Text Editor wrapped in a React Hook Form Controller. * @param {IRHFEditorProps} props - The component props. * @returns {JSX.Element} - The rendered component. */ export const RHFEditor = ({ name, helperText, ...other }: IRHFEditorProps) => { const { control, watch, setValue, formState: { isSubmitSuccessful }, } = useFormContext(); const values = watch(); useEffect(() => { if (values[name] === '


') { setValue(name, '', { shouldValidate: !isSubmitSuccessful, }); } }, [isSubmitSuccessful, name, setValue, values]); return ( ( {error ? error?.message : helperText} ) } {...other} /> )} /> ); };