BlockNote icon indicating copy to clipboard operation
BlockNote copied to clipboard

Cannot read properties of undefined (reading 'dispatch')

Open hsingh-ds opened this issue 1 year ago • 2 comments

Describe the bug I am trying to use replaceBlocks function after initializing the editor. But it is giving an error "Cannot read properties of undefined (reading 'dispatch')"

To Reproduce I have added the link of codesandox: Link to sandbox

hsingh-ds avatar Mar 10 '24 22:03 hsingh-ds

Thanks, this seems to be a bug and I'll look into the root of it.

For now, is there a reason why you can't pass data as initialContent when calling useCreateBlockNote?

YousefED avatar Mar 12 '24 10:03 YousefED

@YousefED I want to replace all blocks with new ones, so I need a way to control the data

Replace blocks doesnt seem to work, I have same issue

tolypash avatar Apr 17 '24 11:04 tolypash

Having same issues, any update on this? @YousefED regarding your comment, I can't use initial content because I need to first convert markdown to blocks using editor.tryParseMarkdownToBlocks so I need my editor initialized first correct?

rickyhonline avatar May 26 '24 15:05 rickyhonline

I'm also having the same problem and it's coming specifically from editor.replaceBlocks()

Here's a sample:

  useEffect(() => {
    async function loadInitialHTML() {
      const blocks = await noteEditor.tryParseMarkdownToBlocks(
        "This is a normal text\n\n# And this is a large heading",
      );
      noteEditor.replaceBlocks(noteEditor.document, blocks);
    }
    loadInitialHTML();
  }, [isLoading]);

I could be wrong but the the issue might be coming from https://github.com/TypeCellOS/BlockNote/blob/99233e5d57e5a4b56eeafd2dd8abe54229dc35fb/packages/core/src/api/blockManipulation/blockManipulation.ts#L189

zaaakher avatar Jun 07 '24 23:06 zaaakher

closed by https://github.com/TypeCellOS/BlockNote/pull/909

YousefED avatar Jul 16 '24 10:07 YousefED