Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Access EditorState from Decorated Component

I'm starting to work with the decorators in draft-js and I'm able to render my components defined in the CompositeDecorator. The documented behavior works great.

That said, I'm trying to figure out how I can access the editorState from within these components. The contentState is the only useful prop passed in, but so far as I can tell I can't resolve the editorState from the contentState.

What I am primarily attempting to do is be able to edit or delete by interacting with the rendered component itself. i.e. opening a dialog to change the entity data. In the onSave() of the dialogForm, I'd need to push the new editorState, but as of right now, it isn't in scope.

Is there a way to access editorState in scope of a decorator component or is there a smarter solution?

like image 560
Blaine Garrett Avatar asked Oct 01 '18 13:10

Blaine Garrett


1 Answers

I don't have an explicit answer (though it seems like a good question!) but I was poking around the DraftJs examples and the TexEditor example seems like it might be useful (if you haven't already consulted it). It uses a custom block, and then passes in props that handle updating the editor state in response to changes in the block component.

Let me know if you figure out a solution, I'd like to know how you approached it in the end.

edit: I know you referenced CompositeDecorator, but wasn't able to find an example of what you describe

like image 98
cojennin Avatar answered Sep 24 '22 13:09

cojennin