draft-js-plugins: Multiple draftjs editors cannot be used on the same page using plugins
Multiple draftjs editors cannot be used on the same page using plugins. All interactions are sent to the last instance on the page.
Clone the repo, install dependencies and change line 77 in /stories/index.js
from
.add('CustomToolbarEditor', () => <CustomToolbarEditor />)
to
.add('CustomToolbarEditor', () => <div><CustomToolbarEditor /><CustomToolbarEditor /></div>)
Now run yarn storybook and open the correct example

Test functionality of both editors and you will see the controls misbehave and target the last editor.

A similar issue is https://github.com/draft-js-plugins/draft-js-plugins/issues/548
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 19 (2 by maintainers)
Thank you, I have converted it to something similar with
useState. With this, each editor get’s its own plugins.This is really an issue for me. Any suggestions or workarounds?
@MartinSeeler
Taking from the comments, in the example at
https://github.com/draft-js-plugins/draft-js-plugins/blob/master/stories/static-toolbar/src/App.js
I have changed the code to look like the following to resolve this. Multiple plugins will work with this method
Helllo everyone!
@MartinSeeler thank you very much for your solution. I had the same issue and it works. But when I do the same with InlineToolbar instead of StaticToolbar, then I keep getting an error
store.getItem(...) is not a function.My main idea is that InlineToolbar needs something extra from the Editor and can’t get it before mount, but I’m not sure how exactly InlineToolbar works.
Do you have any ideas of how I may try to fix this?
Thank you in advance!
@MartinSeeler solution is great, thanks. I did mine with useMemo and got the same effect.
initSelectedPlugins is just a utility function to add plugins from an array of string since I use Editor differently for many purpose.
Thanks again.
As seen above here: https://github.com/draft-js-plugins/draft-js-plugins/issues/1244#issuecomment-467751445
For functional component solution, this is the correct way to go about it. Cheers!
this is Godsend! thanks! @MartinSeeler
If this is still a problem for someone, I had the same issue, and the order of adding components matters for InlineToolbar. It needs to be added
belowthe Editor component.The order for StaticToolbar does not matter.
Man, thanks a lot, been struggling a couple of days with this issue. In my case i’m using the Mentions Plugin. With this solution some styles are getting broken, do u have any idea of what it could be?
Anyways, i moved on a lot with your solution.
Thanks again!
Document this some how, thanks a lot
@ZRCU Did you solve this issue?