Skip to content

Updating EditorOptions does not update editor settings #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
maxswjeon opened this issue Jun 2, 2023 · 6 comments
Closed

Updating EditorOptions does not update editor settings #232

maxswjeon opened this issue Jun 2, 2023 · 6 comments
Assignees

Comments

@maxswjeon
Copy link

Related to #214, following code does not work.

Editor.ts

import { useEffect } from "react";

import {
  BlockNoteView,
  useBlockNote,
} from "@blocknote/react";

import "@blocknote/core/style.css";

type Props = {
  editable: boolean;
}

export default Editor({ editable }: Props) {
  const editor = useBlockNote({
    editable
  });

  // Test Code
  useEffect(() => {
    console.log(editor?.isEditable);
  }, [editable]);

  return <BlockNoteView editor={editor} />;
}

main.ts

import { useState } from "react";

import Editor from './Editor.ts';

export default Main() {
  const [editable, setEditable] = useState(true);

  return (
    <div>
      <button onClick={() => setEditable(!editable)}>Toggle Editable</button>
      <Editor editable={editable} />
    </div>
  );
}

How can I make this work?

@maxswjeon
Copy link
Author

Might a API setEditable would fix it?

@maxswjeon
Copy link
Author

maxswjeon commented Jun 2, 2023

PR #230 will fix my issue (because the reason that I'm trying to set the option is to remove the sidemenu when not focused), but the issue might be worth addressing.

@afurculita
Copy link

Try

const editor = useBlockNote({
    editable
  }, [editable]);

@maxswjeon
Copy link
Author

Thanks, I didn't know that there were dependency list.

@vincelwt
Copy link

I also was stuck on a similar problem with initialContent and the dependency list perfectly solves it :) Might be a good idea to add it to the docs (or I couldn't find it). Thanks for the great library!

@mawnir
Copy link

mawnir commented Jan 29, 2024

this s

Try

const editor = useBlockNote({
    editable
  }, [editable]);

this should be added to docs

@YousefED YousefED self-assigned this Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants