How to test if the content of draftjs editor is empty?
The only idea that I have now is an object comparison against the object returned from this function : EditorState.createEmpty().getCurrentContent()
EditorState is the top-level state object for the editor. It is an Immutable Record that represents the entire state of a Draft editor, including: The current text content state. The current selection state.
Draft. js is used in production on Facebook, including status and comment inputs, Notes, and messenger.com.
Draft. js comes with convertToRaw method that takes in a ContentState object and returns the given ContentState as a raw javascript object. This object can then be stored to a database or wherever you need to store your application's data.
Just use the hasText function on ContentState
:
editorState.getCurrentContent().hasText()
contentState.hasText() && contentState.getPlainText().length > 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With