Skip to content

useObject should support onChunk callback option. #5965

Closed
@kosukeoya

Description

@kosukeoya

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));
      }
    }
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions