1

I can't search on the web the purpose of {" "} in react? What does this do?

<p> Hello I a'm a {" "} programmer </p>
Newboy11
  • 2,778
  • 5
  • 26
  • 40

2 Answers2

-1

It is useful if you want to insert variable's value Example:

const name = "Messi"
<p>Hello, my name is {name}</p>

In your case, a whitespace will be inserted

-1

Curly braces { } are special syntax in JSX. It is used to evaluate a JavaScript expression during compilation. A JavaScript expression can be a variable, function, an object, or any code that resolves into a value.

const isProgrammer  = true;
<p> Hello I am a {isProgrammer ? "programmer" : "non-propgrammer"} </p>

In you case, it will executed and return a white space. There are have 3 white space but it will only show 1 because spaces are compacted in HTML.

<p> Hello I am a {" "} programmer </p> the same with <p> Hello I am a{" "}programmer </p>

Viet Dinh
  • 1,871
  • 1
  • 6
  • 18