rkmax
rkmax

Reputation: 18133

{' '} has some especial meaning on React components

After reading some tutorials, I've found that the authors write {' '} between statements. is it have some special meaning or it's just a convention?

return (
  <form>
    <input type="text" placeholder="Search..." />
    <p>
      <input type="checkbox" />
      {' '}
      Only show products in stock
    </p>
  </form>
);

Upvotes: 0

Views: 995

Answers (2)

Davide Fiorello
Davide Fiorello

Reputation: 71

The whitespace is required to separate the checkbox from the text. Otherwise the JSX compiler remove all the whitespace and the new lines placed just for beautify the code.

You can find a good explanation here.

https://github.com/facebook/jsx/issues/19

Upvotes: 2

Brian Boyko
Brian Boyko

Reputation: 637

It's just a way of hardcoding a space in the HTML.

Upvotes: 0

Related Questions