Rick Rick - 8 months ago 79
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.


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.