diff --git a/src/commons/editor/vditor.tsx b/src/commons/editor/vditor.tsx index 07807fc..895e2ab 100644 --- a/src/commons/editor/vditor.tsx +++ b/src/commons/editor/vditor.tsx @@ -1,10 +1,11 @@ import { createStyles, FormControl, FormHelperText, FormLabel, makeStyles } from '@material-ui/core'; -import { FieldHookConfig, useField } from 'formik'; -import React, { FC, useEffect, useRef, useState } from 'react'; -import Vditor from 'vditor'; -import 'vditor/src/assets/scss/index.scss'; +import { Skeleton } from "@material-ui/lab"; +import { FieldHookConfig, useField } from "formik"; +import React, { FC, useEffect, useRef, useState } from "react"; +import Vditor from "vditor"; +import "vditor/src/assets/scss/index.scss"; -type Props = (FieldHookConfig) & { +type Props = FieldHookConfig & { label?: string; className?: string; }; @@ -12,13 +13,13 @@ type Props = (FieldHookConfig) & { const useStyles = makeStyles((theme) => createStyles({ formControl: { - width: '100%', + width: "100%", }, }) ); export const Editor: FC = ({ label, className, ...props }) => { - const [field, meta, helpers] = useField(props); + const [, meta, helpers] = useField(props); const editor = useRef(null); const [instance, setInstance] = useState(() => null); const [containerKey] = useState(() => Math.random().toString(36).slice(2, 8)); @@ -36,10 +37,13 @@ export const Editor: FC = ({ label, className, ...props }) => { value: meta.initialValue, input: (val) => helpers.setValue(val), blur: () => helpers.setTouched(true), + after: () => { + setInstance(_instance); + }, }); - setInstance(_instance); + return () => { - instance?.destroy(); + _instance?.destroy(); }; }, []); @@ -49,6 +53,15 @@ export const Editor: FC = ({ label, className, ...props }) => { {label}
{meta.error && {meta.error}} + {instance ? null : ( + + )} ); }; \ No newline at end of file