TypeCellOS / BlockNote

A React Rich Text Editor that's block-based (Notion style) and extensible. Built on top of Prosemirror and Tiptap.

Home Page:https://www.blocknotejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About the best rerendering strategy

UmizDemud opened this issue · comments

Hi everyone, I had an issue which I found hard to solve. Can you help out?

How would I go about rerendering the Editor, when the state that holds its content changes. Please take a quick look on the below example. All I need is to update the editor when the component prop text updates.

...
const MyEditor = ({text}: {text: string}) => {
  const editor: BlockNoteEditor = useBlockNote({
    editable: true,
    initialContent: (text as string).length !== 0 ? JSON.parse(text) as PartialBlock[] : undefined,
    onEditorContentChange: (editor) => {
      doSomething()
    }
  })
  
    return (
      <BlockNoteView
        editor={editor}
        theme={resolvedTheme === "dark" ? "dark" : "light"}
        className=""
      >
        <FormattingToolbarPositioner editor={editor} />
        <HyperlinkToolbarPositioner editor={editor} />
        <SlashMenuPositioner editor={editor} />
      </BlockNoteView>
    )
}

P.S - Wonderful work with this product, I'd be more than happy to return and collab in the future!

Hi,

Your code sample seems from an old version, I'd recommend upgrading first and then file a new issue if you're still having trouble!