Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

convertFromRaw returns an Array of ContentBlocks not a ContentState #28

Closed
dustin-H opened this issue Feb 23, 2016 · 9 comments
Closed

Comments

@dustin-H
Copy link
Contributor

Hi there,

As documented here the function convertFromRaw should return a ContentState object.

However it returns an array of ContentBlock objects.

This works:

var data = '{"entityMap":{},"blocks":[{"key":"4oah6","text":"Dieser Test","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":7,"length":4,"style":"BOLD"},{"offset":0,"length":11,"style":"CODE"},{"offset":0,"length":6,"style":"ITALIC"}],"entityRanges":[]}]}'

var json = JSON.parse(data)

var blockArray = convertFromRaw(json);

var contentState = ContentState.createFromBlockArray(blockArray);

var editorState = EditorState.createWithContent(contentState);

However this throws an error:

var contentState = convertFromRaw(json);

var editorState = EditorState.createWithContent(contentState);

Error:
screen shot 2016-02-23 at 00 56 54

Is this a mistake in the docs or a bug?

@hellendag
Copy link

Great catch. It's a mistake in the docs.

@dustin-H
Copy link
Contributor Author

Ok, thanks... PR is in progress ;)

@maksimsemenov
Copy link

Hi there,

There is still mistake in the docs: https://facebook.github.io/draft-js/docs/api-reference-data-conversion.html#content

convertFromRaw(rawState: RawDraftContentState): ContentState

@dustin-H
Copy link
Contributor Author

Where? Can't find it.

@maksimsemenov
Copy link

Here is a screenshot of this page: https://facebook.github.io/draft-js/docs/api-reference-data-conversion.html#content

I marked the mistake with the red rectangle
group

@dustin-H
Copy link
Contributor Author

dustin-H commented Apr 29, 2016

What do you think should be there instead?

@maksimsemenov
Copy link

From conversation above instead of ContentState there should be array of ContentBlocks

@dustin-H
Copy link
Contributor Author

Ah, now I see. I had fixed this in PR.

However, it was changed it back by @hellendag here

This was because the return type has changed here.

In PR #333 it was discussed a bit.

So docs are correct.

@maksimsemenov
Copy link

Oh, thanks. I used a 0.5.0 version and it was returning an array of ContentBlocks, so I thought that there is a mistake in docs. Now, after I've updated to 0.6.0 it works fine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants