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

useSlate hook holds old editor instance after recreating a new one #5709

Open
skorenb opened this issue Aug 28, 2024 · 1 comment
Open

useSlate hook holds old editor instance after recreating a new one #5709

skorenb opened this issue Aug 28, 2024 · 1 comment
Labels

Comments

@skorenb
Copy link

skorenb commented Aug 28, 2024

Description
I have the slate component defined as <Slate editor={editor} initialValue={editor.children}/>
When i want to recreate editor instance. Internally there is no any mechanism to update the context in order to get useSlate hook work properly.

Expectation
The react context is updated due to changed editor externally

Question
In general should <Slate/> component update context in such situation or an editor instance is considered as singleton object? What pitfalls are there? If it's intentional shoud i reuse existing editor instance by changing children property?

Environment

  • Slate Version: 0.103.0
  • Slate-React Version: 0.109.0

Context
In our app due to its architecture an editor gets recreated after saving&loading text document.

@skorenb skorenb added the bug label Aug 28, 2024
@bmingles
Copy link
Contributor

bmingles commented Sep 22, 2024

@skorenb Is it an option for you to update the ‘initialValue’ reference whenever your editor changes? IIR, the context does update if the value passed to that prop changes.

I misremembered that. The way I’ve done this is:

editor.children = newValueArray
editor.onChange()

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