plane/apps/app/components/tiptap/hooks/useDebouncedUpdates.tsx

19 lines
490 B
TypeScript
Raw Normal View History

2023-08-09 04:12:57 +00:00
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);
;