Closed
Description
Description
Although onFinish is executed after all chunks have been read, there are cases where we want it to be executed every time a chunk is read.
I would like to call tiptap's setContent after each chunk read of the useObject. Here is an implementation I can do right now
const Component = () => {
const { object } = useObject({ api: 'http://example.com' });
useEffect(() => {
if (object.content) {
editor?.commands.setContent(md.render(object.content));
}
}, [object.content, editor])
}
However, this code will result in an infinite loop because the editor instance is updated each time setContent is executed.
It would be better to implement something like the following
const Component = () => {
const { object } = useObject({ api: 'http://example.com' }, {
onChunk: (object) => {
if (object.content) {
editor?.commands.setContent(md.render(object.content));
}
}
});
}