fix: improve the texteditor save module

This commit is contained in:
MTG2000
2022-04-27 17:09:01 +03:00
parent cad9acdfac
commit 4d8cad601e

View File

@@ -1,29 +1,29 @@
import React, { useCallback } from 'react'
import { EditorComponent, Remirror, useHelpers, useRemirror, useEvent, useEditorState } from '@remirror/react';
import { useHelpers, useEvent, useRemirrorContext } from '@remirror/react';
import { Control, useController } from 'react-hook-form';
import { useDebouncedCallback } from '@react-hookz/web';
interface Props {
control?: Control,
name?: string,
}
export default function SaveModule(props: Props) {
const state = useEditorState()
const { getMarkdown } = useHelpers();
const { field: { onChange, onBlur } } = useController({
control: props.control,
name: props.name ?? 'content'
})
const listener = (d: any) => {
onChange(getMarkdown(state));
onBlur()
};
const { getMarkdown } = useHelpers();
useEvent('blur', listener)
const changeCallback = useDebouncedCallback(ctx => {
const { state } = ctx;
onChange(getMarkdown(state));
}, [], 500)
useRemirrorContext(changeCallback)
useEvent('blur', () => onBlur())
return <></>
}