question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update the decorators in componentDidUpdate

See original GitHub issue

Describe the feature

For now, the decorators are set in componentDidMount https://github.com/draft-js-plugins/draft-js-plugins/blob/9e97f6ce488dbc20c24a0440a6336f366003683a/packages/editor/src/Editor/index.tsx#L103

But there are not reset on update https://github.com/draft-js-plugins/draft-js-plugins/blob/9e97f6ce488dbc20c24a0440a6336f366003683a/packages/editor/src/Editor/index.tsx#L114

So there is no way to dynamically update the decorator as described in the documentation: https://draftjs.org/docs/advanced-topics-decorators#setting-new-decorators

I could be good to update the decorators also in componentDidUpdate.

What do you think?

Motivation

I am trying to implement a plugin to show the cursor of other users in the context of a collaborative editor. I have the cursor positions of the other users as SelectionState. My cursor plugin is parametrized by these cursors and implement decorators which show these cursors in the text. As the cursor position change over time, I need that the editor update its decorator accordingly.

Here is another example of dynamic decorator which seems not doable with draft-js-plugins (highlight search text) https://reactrocket.com/post/draft-js-search-and-replace/

Did I miss something?

Possible implementations

Related Issues

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
BSeblucommented, Mar 1, 2022

I had an issue with a decorator, whose purpose is basically displaying a drop-down. When sie options change, i get a new decorator instance. But this new instance is not used because the decorators are only applied in componentDidMount. I worked around it by replacing my decorators directly with EditorState.set, but it took me quite a long time to figure it out. For me it was not obvious, that the decorators are not updated when the props change.

0reactions
iamswain25commented, Oct 23, 2022
 React.useEffect(() => {
    if (!editorState.getDecorator()) {
      editorRef.current?.componentDidMount();
    }
  }, [editorState]);
Read more comments on GitHub >

github_iconTop Results From Across the Web

stenciljs - Run componentDidUpdate only on changes within ...
Is there a way I can tell (maybe by custom decorators) componentDidUpdate to only run if the update was triggered from within this...
Read more >
Enhancing React Components with decorators - Medium
Decorators are a feature that didn't make it in ES7, but are currently a stage 2 proposal so it's fair to assume they're...
Read more >
React Decorators - OYOTech
Decorators are an experimental feature that may change in future releases. ... and Perf.end() inside componentDidUpdate() .
Read more >
Component API - Stencil.js
Decorators are a pure compiler-time construction used by stencil to collect all the metadata about a component, the properties, attributes and methods it ......
Read more >
Using componentDidUpdate() in React — Developer's Guide
The componentDidUpdate() method is an update method that is invoked after the componentDidMount() method and this happens immediately after ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found