Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate unicode and variable

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

{'\u{1F680}'} become {'\u{MyVar}'}
like image 236
Smaïne Avatar asked Feb 03 '19 21:02

Smaïne


1 Answers

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'>
like image 126
Treycos Avatar answered Oct 14 '22 01:10

Treycos