How to concatenate unicode and variable in ReactJS ?

Unicode: Unicode is an encoding standard for all characters in the universe. Every language code and symbol in this world is assigned by Unicode. There is no encoding standard that supports all languages, By using Unicode standard, we can retrieve and combine data with all language combinations.

Example: 

U+2192

In the above example, a right-facing arrow is represented in Unicode by U+2192.

How to create React Application:

  • Step 1: Create a React application using the following command.

     npx create-react-app zambiatek
  • Step 2: After creating your project folder i.e. zambiatek, move to it using the following command.

    cd zambiatek
  • Project Structure:

    Folder structure

    How to concatenate Unicode and variable in ReactJS: To concatenate we first convert Unicode into its numerical value and for that, we will use parseInt.

parseInt(Unicode,base)

Now, this numerical value needs to be converted into its character and for that, we can use

String.fromCodePoint(numericalValue).

Example: Make the following changes to your App.js file

App.js




import React from 'react'
    const App = ({ unicode }) => {
  
    return(
  
       <h1>
           This is a Right arrow
           {String.fromCodePoint(parseInt(unicode,16))}
       </h1>
   )}
export default App;


Now import this App.js file in your index.js file(by default it is already being imported) and pass the value of Unicode in the App component.

index.js




import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
  
    ReactDOM.render(
    <React.StrictMode>
       <App unicode='2192'/>
    </React.StrictMode>,
  
   document.getElementById('root')
  
    );


Now run the local server using the following command within the react-app directory  

npm start

Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button