将 EmojiOne 与 React 结合使用
Using EmojiOne With React
我一直在尝试将 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:')}
)
这给了我
这是检查元素中的样子:
据我所知,emojione 库将图像代码作为文本而不是元素放入 React。知道为什么吗?
谢谢!
React 正在转义 EmojiOne 的输出以避免跨站点脚本攻击。您可以(但可能不应该...)使用 dangerouslySetInnerHTML
将 EmojiOne 的输出注入为 "actual" HTML。
有人已经写了一个可能有用的 React EmojiOne 包装器:https://github.com/pladaria/react-emojione
有关 dangerouslySetInnerHTML
的更多信息以及应避免的原因,请查看:https://facebook.github.io/react/tips/dangerously-set-inner-html.html
我一直在尝试将 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:')}
)
这给了我
这是检查元素中的样子:
据我所知,emojione 库将图像代码作为文本而不是元素放入 React。知道为什么吗?
谢谢!
React 正在转义 EmojiOne 的输出以避免跨站点脚本攻击。您可以(但可能不应该...)使用 dangerouslySetInnerHTML
将 EmojiOne 的输出注入为 "actual" HTML。
有人已经写了一个可能有用的 React EmojiOne 包装器:https://github.com/pladaria/react-emojione
有关 dangerouslySetInnerHTML
的更多信息以及应避免的原因,请查看:https://facebook.github.io/react/tips/dangerously-set-inner-html.html