️✍️述 - Emoji使用

需求:直播间进行聊天时添加emoji表情的使用

即:React中emoji的开发使用

解决:

// emoji-lib
npm i emoji-picker-react --save

// component

<EmojiPicker
  onEmojiClick={(e) => {
    const ej = String.fromCodePoint('0x' + e);

    this.setState({
      talkvalue: `${this.state.talkvalue}${ej}`,
      emojiShow: false,
    });
  }}
/>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

核心:

emoji对应的unicode编码进行转换并显示

const ej = String.fromCodePoint('0x' + e);


其他解决方案

Lib Description
twemoji Twitter的开源项目 github简易教程
react-emojify github
react-emojione github