|
1 | 1 | # Frequently Asked Questions
|
2 | 2 |
|
3 |
| -## How to reset the content? |
4 |
| - |
5 |
| -Since the decorators are stored in the EditorState it's important to not reset |
6 |
| -the complete EditorState. The proper way is to reset the ContentState which is |
7 |
| -part of the EditorState. In addition this ensures proper undo/redo behavior. |
8 |
| - |
9 |
| -Right: |
10 |
| -```js |
11 |
| -import { EditorState, ContentState } from 'draft-js'; |
12 |
| - |
13 |
| -const editorState = EditorState.push(this.state.editorState, ContentState.createFromText('')); |
14 |
| -this.setState({ editorState }); |
15 |
| -``` |
16 |
| - |
17 |
| -Wrong: |
18 |
| -```js |
19 |
| -import { EditorState } from 'draft-js'; |
20 |
| - |
21 |
| -this.setState({ editorState: EditorState.createEmpty() }) |
22 |
| -``` |
23 |
| - |
24 |
| -## Why are mentions broken after using `convertFromRaw` and throwing an error? |
25 |
| - |
26 |
| -__Please Note: this has been fixed in the beta version, from now on you can use a plain array for your mention suggestions__ |
27 |
| - |
28 |
| -We design the API to accept an Immutable Map for a Mention. After saving your data structure to the server and using `convertFromRaw`, the mentions in there are plain objects. I (Nik) believe this is a flaw in our design and the mention data should be a plain object. Hint: we might fix this with v2.0.0 of the mentions plugin. |
29 |
| - |
30 |
| -What you can do now is fixing the datastructure before converting it: |
31 |
| - |
32 |
| -```JS |
33 |
| -import { fromJS} from 'immutable'; |
34 |
| -import forEach from 'lodash/forEach'; |
35 |
| - |
36 |
| -forEach(rawContent.entityMap, function(value, key) { |
37 |
| - value.data.mention = fromJS(value.data.mention) |
38 |
| -}) |
39 |
| - |
40 |
| -const contentState = Draft.convertFromRaw(rawContent) |
41 |
| -const editorState = Draft.EditorState.createWithContent(contentState) |
42 |
| -``` |
43 |
| - |
44 | 3 | ## Why is there no Popover for Mentions/Emoji plugin?
|
45 | 4 |
|
46 | 5 | The MentionSuggestions/EmojiSuggestions component is internally connected to the
|
|
0 commit comments