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.

Setting myState from the outside after component is mount will drop the decorators

See original GitHub issue

say you have

<Editor editorState={this.props.myState} onChange={this.onChange} /> 

After the editor is mounting, if the parent component passes down a new state (through the myState props) to the Editor, the Editor will drop all the plugin decorators, since the decorators are set only during componentWillMount.

Let me know if the explanation is not clear, and I will create a minimal reproduction on jsbin or similar

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
gnestorcommented, Feb 8, 2018

My temporary solution is to call componentWillMount() on my <Editor> instance because componentWillMount is where all of the decorators are resolved and merged into the editor state.

I’m calling the following in my container component’s componentWillReceiveProps so that I can update the editor state in response to next props:

this.setState({ editorState }, () => {
    this.editor.componentWillMount();
});

Assuming the following:

<Editor
  editorState={this.state.editorState}
  onChange={this.onChange}
  plugins={plugins}
  ref={element => {
    this.editor = element;
  }}
/>

https://github.com/draft-js-plugins/draft-js-plugins/pull/526 attempted to add a reloadDecorators method to the <Editor> component which accomplishes the end result. However, I think that this should just work for users for this library. Apparently, simply resolving the decorators and merging them into the editor state in componentWillMount is not enough. However, doing it in componentWillReceiveProps is probably too much and I’ve observed it doing strange things with the cursor.

My specific use case: I have a single page application that lists available docs and allows users to click on a doc to view/edit. When a user loads the app on a doc route, the decorators are all intact and the doc renders correctly. However, if the user loads the app on the docs route or navigates away from a doc route and back to another doc route (essentially, after the initial instance of the doc component in unmounted), many decorators are missing, such as linkify, link, mention, emoji, images, etc.

1reaction
izzappelcommented, Feb 21, 2018

@gnestor yes exactly

My temporary solution looks very similar:

	componentDidMount() {
		this.editor.componentWillMount();
	}

Unfortunately I have no other ideas to fix my problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I manage state outside of React Final Form?
I guess that makes sense. I'm storing the state in the top-most App component. The form itself can be unmounted and re-mounted, but...
Read more >
useEffect(fn, []) is not the new componentDidMount()
First, let's talk about the timing of each. componentDidMount runs after the component mounts. As the docs say, if you set state immediately...
Read more >
Recovery and Rebirth: The Age of the Renaissance
n How did the fall of Constantinople to the Ottoman Turks lead to changes in trade, diplomacy, and society after 1453?
Read more >
A Guide to USPS Mailbox Regulations - Mailboss
Guide to USPS regulations for mailbox installation of curbside mailboxes, locking mail boxes, wall mount units and residential package ...
Read more >
Installing a Garage Heater : 8 Steps - Instructables
1. Ideally, you would want to position the heater in the coldest location in the garage at a 45 degree angle aimed at...
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