plane/apps/app/components/tiptap/hooks/useDebouncedUpdates.tsx
2023-08-09 09:42:57 +05:30

19 lines
490 B
TypeScript

import { useDebouncedCallback } from 'use-debounce';
import { Editor as CoreEditor } from "@tiptap/core";
type DebouncedUpdatesProps = {
onChange?: (json: any, html: string) => void;
editor: CoreEditor | null;
};
export const useDebouncedUpdates = (props: DebouncedUpdatesProps) =>
useDebouncedCallback(async () => {
setTimeout(async () => {
if (props.onChange) {
props.onChange(props.editor.getJSON(), props.editor.getHTML());
}
}, 500);
}, 1000);
;