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

State is uncontrolled in [email protected] #4646

Closed
lynxtaa opened this issue Nov 8, 2021 · 3 comments
Closed

State is uncontrolled in [email protected] #4646

lynxtaa opened this issue Nov 8, 2021 · 3 comments
Labels

Comments

@lynxtaa
Copy link

lynxtaa commented Nov 8, 2021

Description
Changing state programmatically won't work in [email protected]. For example, setting value from useEffect doesn't work:

  useEffect(() => {
    let timer = setTimeout(
      () =>
        setValue([
          { type: "paragraph", children: [{ text: "Hello world!" }] },
        ]),
      5000
    );

    return function () {
      clearTimeout(timer);
    };
  }, []);

  return (
    <Slate editor={editor} value={value} onChange={setValue}>
      <Editable renderElement={renderElement} />
    </Slate>
  );

Recording
I really hope sandbox will be sufficient for observing this behaviour.

Sandbox
https://codesandbox.io/s/slate-set-value-4fxxc?file=/src/Editor/index.js

Steps
To reproduce the behavior:

  1. Go to sandbox https://codesandbox.io/s/slate-set-value-4fxxc?file=/src/Editor/index.js
  2. Wait 5 sec
  3. Editor won't show text Hello world. But it should
  4. Set in package.json [email protected]
  5. Now it works

Expectation
I expect slate state to be controlled as in [email protected]

Environment

  • Slate Version: 0.70.0
  • Operating System: Windows
  • Browser: Firefox, Chrome
@lynxtaa lynxtaa added the bug label Nov 8, 2021
@lynxtaa lynxtaa changed the title State is uncontrolled in slate-react > 0.66.7 State is uncontrolled in [email protected] Nov 8, 2021
@lynxtaa
Copy link
Author

lynxtaa commented Nov 8, 2021

I think it's because of #4540

If so, what is the best way right now for changing state as a whole?

@aboveyunhai
Copy link

aboveyunhai commented Nov 8, 2021

Refer to #4612 and the PR
it can be changed directly by editor.children = value above your return statement, I changed mine to this way and it works out for general first render, but I'm not sure about the real time cooperative editing.
The approach is still questionable for me. I don't have a complex project that is able to test against the effect of this breaking change.

@lynxtaa
Copy link
Author

lynxtaa commented Nov 8, 2021

@aboveyunhai Thanks! Closing as duplicate

@lynxtaa lynxtaa closed this as completed Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants