johannchopin
johannchopin

Reputation: 14844

Draftjs: Argument of type 'htmlConverter' is not assignable to parameter of type 'ContentState'

I use convertFromHTML from draft-convert to convert my html string to an object that can be called as parameter from EditorState.createWithContent from draftjs (as explained in the README).

But when I do something like that:

const textToConvert = '<p>A paragraph</p>'
editorState = EditorState.createWithContent(convertFromHTML(textToConvert));
                                                            ~~~~~~~~~~~~~

I get a type definition error from TypeScript:

Type 'string' has no properties in common with type 'IConvertFromHTMLConfig'

Have I missed something because like that the WYSIWYG editor is working pretty well.

Here is the link of the sandbox

Upvotes: 0

Views: 1229

Answers (1)

Aleksey
Aleksey

Reputation: 81

It must help you )

const textToConvert = '<p>A paragraph</p>';
const blocksFromHTML = convertFromHTML(textToConvert);

const [editorState, setEditorState] = React.useState(
        EditorState.createWithContent(
            ContentState.createFromBlockArray(blocksFromHTML.contentBlocks, blocksFromHTML.entityMap)
        )
    );

Upvotes: 5

Related Questions