从服务器获取contentState
后,"转换自Raw"
我在编辑器中显示它,它只显示本机的表情符号。
事件虽然在发送到服务器之前,聊天编辑器显示了正确的表情符号
这是过程
const contentState = convertFromRaw(JSON.parse(comment.message))
const editorState = EditorState.createWithContent(contentState)
<ChatTemplate
user={currentUser === comment.userId}
value={editorState}
time={moment(comment.createdAt).startOf('second').fromNow()} />
和编辑
const ChatTemplate = (p)=>(
<div className='globalMassage-cont' data-user={p.user} >
<div className='globalMassage-value'>
<Editor
editorState={p.value}
plugins={plugins}
readOnly
/>
</div>
</div>
)
导入和常量
import Editor, { createEditorStateWithText } from "draft-js-plugins-editor";
import createEmojiPlugin from "draft-js-emoji-plugin";
import { EditorState, ContentState, convertFromRaw } from "draft-js";
const emojiPlugin = createEmojiPlugin();
const { EmojiSuggestions, EmojiSelect } = emojiPlugin;
const plugins = [emojiPlugin];