Hi Friends 👋,

Welcome To Infinitbility! ❤️

To concat string in react js, you can use + plus operator or ES6 string interpolation both will help for your string concatenation.

In the following example, we will take the sample string variable, and do concatenation using both ways ( plus operator and string interpolation ).

let text = "infinitbility.com";

// using plus operator
let str1 = "One of the best site is " + text;
console.log(str1) // "One of the best site is infinitbility.com"

// string interpolation
let str2 = `One of the best site is ${text}`;
console.log(str2) // "One of the best site is infinitbility.com"

Today, I’m going to show you How do i concat string in react js, as mentioned above here, I’m going to use the plus operator and string interpolation to concatenate two strings.

Let’s start today’s tutorial how do you concat string and variable in react js?

In this example, we will do

  1. take an example of a string state
  2. use the plus operator and string interpolation
  3. print the concatenation string on the page screen
import React, { useState, useEffect } from "react";
export default function App() {
  const [sampleString, setSampleString] = useState("infinitbility");

  useEffect(() => {
    // using plus operator
    let str1 = "One of the best site is " + sampleString;
    console.log(str1)
  }, []);

  return (
    <div className="App">
      <h1>{`One of the best site is ${sampleString}`}</h1>
    </div>
  );
}

In the above react js example, we have taken examples of both ways ( plus operator and string interpolation ) and printed output in the console and page screen.

I hope it helps you, All the best 👍.