我是 React 的新手,我在显示动态 unicode 值时遇到了一些问题?
{'u{1F680}'} become {'u{MyVar}'}
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'>