How to save the editor's content with delay? #2871
Answered
by
amirhhashemi
amirhhashemi
asked this question in
Questions & Help
-
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.
Answered by
amirhhashemi
Jun 12, 2022
Replies: 1 comment 3 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.
3 replies
Answer selected by
amirhhashemi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works for me: