Inconsistency with decorators and EditorState
See original GitHub issueUsing version 1.1.0
.
lets say we have this function:
function createState(text) {
return EditorState.createWithContent(
ContentState.createFromText(text)
);
}
each time we create a new EditorState
, we need to manually set the decorators. Yet, the first state we send gets the decorators from the plugins.
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (11 by maintainers)
Top Results From Across the Web
How to Access EditorState from Decorated Component
So I just ran into this issue and resolved it using decorator ... in the editor state your in performance (and visual rendering)...
Read more >Issues and Pitfalls - Draft.js
When delays are introduced to a React application with a Draft editor, however, it is possible to cause significant interaction problems.
Read more >How to Access EditorState from Decorated Component-Reactjs
So I just ran into this issue and resolved it using decorator properties. { strategy: handleSentenceStrategy, component: SentenceComponent, props: { ...
Read more >Best practices when working with draft js - React Rocket
js editor with lots of decorators and custom block components can easily cause performance issues, especially for large documents. Draft.js ...
Read more >Web Developer Playbook: Rich Text Editor - Xiaoyun Yang
Use EditorState.createWithContent , which returns a new EditorState object based on the ContentState and decorator provided. As we will see ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just had a quick go at this, and it doesn’t seem possible (at least easily) anymore: to create a new set of combined decorators,
createCompositeDecorator
needs to be passedgetEditorState
andsetEditorState
, which are only available within the component itself once instantiated.I’m not familiar enough with the codebase to know if it could be refactored in a way that makes this easier.
The only way I currently see of making such a util work would be to create it as a prototype method, and have people retrieve the Editor instance using a
ref
attribute, from which they’d be able to access the util. Doable but really not the best api.My use-case (forcing the re-rendering of decorators) doesn’t require this solution specifically, I’ll implement another simple one instead, but the idea in this thread is great and would make a larger number of use-cases possible 👍
I personally have the feeling that the intention here is really to “re-build” the editor with a new blank state so it makes sense to re-instantiate the editor (and thus the decorators). The solution could be to just abstract that part in a function that returns the editor’s initial editorState to avoid the repetition.