连接unicode和变量 [英] Concatenate unicode and variable

查看:32
本文介绍了连接unicode和变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 React 的新手,我在显示动态 unicode 值时遇到了一些问题?

I'm newbie in React and I have some issue to display dynamic unicode value ?

{'\u{1F680}'} become {'\u{MyVar}'}

推荐答案

String.fromCodePoint 将从其数字代码点获取字符,parseInt 将从十六进制字符串中获取数字.

String.fromCodePoint will get you the character from its numeric code point, and parseInt will get you the number from a hex string.

您的转换将如下所示:String.fromCodePoint(parseInt(MyVariable, 16))

工作示例:

const App = ({ unicode }) => <p> 3, 2, 1, GO ! {String.fromCodePoint(parseInt(unicode, 16))}</p>

ReactDOM.render(<App unicode='1F680'/>, document.getElementById('root'))

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.5.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.5.2/umd/react-dom.production.min.js"></script>
<div id='root'>

这篇关于连接unicode和变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆