【问题标题】:Using EmojiOne With React将 EmojiOne 与 React 一起使用
【发布时间】:2016-08-10 15:13:07
【问题描述】:

我一直在尝试将 EmojiOne 与 React.js 与标准 .toImage 一起使用(请参阅文档 http://git.emojione.com/demos/latest/jstoimage.html)。这是我的代码的样子,或多或少

//react imports
import emoji from 'emojione';
//class component etc. render
return(
//other things from component
    {emoji.toImage(':smile:')}
)

这给了我

link to image

这是检查元素中的样子:

link to image

据我所知,emojione 库将图像代码作为文本而不是元素放入 React。知道为什么吗?

谢谢!

【问题讨论】:

    标签: reactjs emojione


    【解决方案1】:

    React 正在转义 EmojiOne 的输出以避免跨站点脚本攻击。您可以(但可能不应该......)使用dangerouslySetInnerHTML 将 EmojiOne 的输出作为“实际”HTML 注入。

    有人已经编写了一个可能有用的 React EmojiOne 包装器:https://github.com/pladaria/react-emojione

    有关dangerouslySetInnerHTML 的更多信息以及应避免使用它的原因,请查看:https://facebook.github.io/react/tips/dangerously-set-inner-html.html

    【讨论】:

    • 谢谢! react-emojione 看起来像是使用了旧版本的 emojione。但我想我可能已经想通了,我会在一分钟内发布它
    • @EliYazdi 我想你忘了张贴你的发现。请发布它,因为我面临同样的问题
    • @EliYazdi 你有一个可行的解决方案吗,我也面临同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 2018-07-18
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多