Double symbol issue
I'm trying to make collaborative editing for Draft based on CRDT. For this I need to store content state in database and send it between clients, while selection state can be stored in component's state. For this I deconstruct entity state in onChange handler and then construct it again in render function.
The problem is that on symbol input, it triggers onChange two times and and ends up with two symbols in editor instead of one.
For your convenience, I created an example that reproduces problem. It is fork from rich example and saves everything in state.
You might consider handleBeforeInput.
@gscottolson I'm trying to use handleBeforeInput. I assume, that you mean that I should reject some symbols by returning true, but it is called just once, before onChange is called two times. So I can reject all input or nothing.
I believe that modifying the editor state within your onChange handler might be contributing to your problem. Here is an excerpt from another issue:
When you changed to a new
ContentStatewithinhandleChange, thenativelyRenderedContentvalue and your newContentStatedid not match up. When this occurs, the component will re-render, because it believes that the currentContentStateis not natively rendered. The event still occurs and the character is natively inserted, but your re-render also takes place. The character thus appears twice.
I think you can use EditorState.push instead of creating a new EditorState from scratch for each component render.
@gscottolson EditorState.push works. Looks like I missed this moment in docs. Thanks.