Rick Rick -4 years ago 257
React JSX Question

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

I have this in some React documentation, as well as screencasts. People will write

{ " " }
inside of their JSX templates.

Why do they do this? It looks like they are using it as an alternative to line breaks, but I don't see that explicitly explained anywhere.

Answer Source

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.


 <a>some Text</a>

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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download