Why do people put { " " } in their React / JSX?

This is used to put an explicit space in a text block, since leading and trailing spaces are ignored at compile/transformation time when there is another tag.

Example:

<div>
 Text
 <a>some Text</a>
</div>

Will result with Textsome Text on the screen. (see the missing space)

<div>
 Text{' '}
 <a>some Text</a>
</div>

Will result as wanted with Text some Text on the screen.


It is used to add some leading or trailing spaces

render() {
  return ( 
    <div>
      My name is{' '}
      <span> Piyush </span>
    </div>
  );
}

Tags:

Reactjs

Jsx