How to save the editor's content with delay? #2871
-
I want to save the editor's content in a database as I type something, but I don't want to save the content for every single character change, it puts too much pressure on the server. I would rather save it when the editor remains untouched for about 2 seconds. const Editor = () => {
const [content, setContent] = useState("");
useEffect(() => {
const timer = setTimeout(() => {
// save
}, 2000)
return () => {
clearTimeout(timer)
}
}, [content])
} But I can't find a way to do this in tiptap. maybe I can store the last time that I saved the content in a place? and do the same logic as react in the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
This works for me: import { useDebounce } from 'use-debounce';
const Editor = () => {
// create editor instance and other stuff
const [debouncedEditor] = useDebounce(editor?.state.doc.content, 2000);
useEffect(() => {
if (debouncedEditor) {
// save
}
}, [debouncedEditor]);
} |
Beta Was this translation helpful? Give feedback.
-
Hey, I have a different question, how do you guys manage saving the updated document to your server? do you only patch the changes or replace the whole document each time? TipTap doesn't output ID'ed nodes so it's not easy to detect changes and only update those on the server |
Beta Was this translation helpful? Give feedback.
This works for me: