I'm newbie in React and I have some issue to display dynamic unicode value ?
{'\u{1F680}'} become {'\u{MyVar}'}
String.fromCodePoint
will get you the character from its numeric code point, and parseInt
will get you the number from a hex string.
Your conversion will look like the following : String.fromCodePoint(parseInt(MyVariable, 16))
Working example :
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'>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With