2

从服务器获取contentState并“从原始转换”后,我在编辑器中显示它,它只显示本机表情符号。

事件尽管在将其发送到服务器之前,聊天编辑器会正确显示表情符号

这是过程

    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];
4

0 回答 0