Skip to content
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

fix: onNodesChange now updates its state correctly #564

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akucinskii
Copy link

@akucinskii akucinskii commented Sep 29, 2023

There is a problem with onNodesChange using state from the initialization of component

This fixes it at now it updates the value correctly:

Old code example:

 console.log(mode) //1st call: firstMode, 2nd call: secondMode
  return (
    <Editor
      enabled={true}
      onNodesChange={(query) => {
        console.log(mode); //1st call: firstMode, 2nd call: firstMode (always firstMode no matter what)
      
      }}
      resolver={{ ... }}
    >
      {children}
    </Editor>
  );

New code example:

 console.log(mode) //1st call: firstMode, 2nd call: secondMode
  return (
    <Editor
      enabled={true}
      onNodesChange={(query) => {
        console.log(mode); //1st call: firstMode, 2nd call: secondMode
      
      }}
      resolver={{ ... }}
    >
      {children}
    </Editor>
  );

Screenshot of working example:

image

Code of this example screenshot:

const [count, setCount] = useState(0);

 return (
   <>
     <Editor
       resolver={{
         Item: Item,
         Toolbox: Toolbox,
       }}
       onNodesChange={() => {
         console.log('nodes changed, current count state: ', count);
       }}
     >
...

@akucinskii akucinskii changed the title fix: onNodesChange not updating props fix: onNodesChange now uses correct props Sep 29, 2023
@akucinskii akucinskii changed the title fix: onNodesChange now uses correct props fix: onNodesChange now updates its state correctly Sep 29, 2023
@Savuelo
Copy link

Savuelo commented Oct 2, 2023

Same issue here please fix

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

Successfully merging this pull request may close these issues.

None yet

2 participants