我是React的新手,我在显示动态unicode值时遇到一些问题?
{'\u{1F680}'} become {'\u{MyVar}'}
答案 0 :(得分:1)
String.fromCodePoint
将使您从数字代码点获得字符,而parseInt
将使您从十六进制字符串获得数字。
您的转换将如下所示: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'>