- React Design Patterns and Best Practices(Second Edition)
- Carlos Santana Roldán
- 177字
- 2021-06-24 15:43:38
Spaces
There's one thing that could be a little bit tricky in the beginning and, again, it concerns the fact that we should always keep in mind that JSX is not HTML, even if it has an XML-like syntax.
JSX handles the spaces between text and elements differently from HTML, in a way that's counter-intuitive.
Consider the following snippet:
<div>
<span>My</span>
name is
<span>Carlos</span>
</div>
In the browser, which interprets HTML, this code would give you "My name is Carlos", which is exactly what we expect.
In JSX, the same code would be rendered as MynameisCarlos, which is because the three nested lines get transpiled as individual children of the div element, without taking the spaces into account. A common solution to get the same output is putting a space explicitly between the elements as follows:
<div>
<span>My</span>
{' '}
name is
{' '}
<span>Carlos</span>
</div>
As you may have noticed, we are using an empty string wrapped inside a JavaScript expression to force the compiler to apply the space between the elements.
- 物聯網智慧安監技術
- SEO 20日
- JBoss EAP6 High Availability
- Proxmox High Availability
- Drush User’s Guide
- PLC、現場總線及工業網絡實用技術速成
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- 網絡AI+:2030后的未來網絡
- 物聯網工程概論
- 異構蜂窩網絡關鍵理論與技術
- 5G非正交多址接入技術:理論、算法與實現
- Qt5 Python GUI Programming Cookbook
- 圖神經網絡前沿
- 物聯網與智慧廣電
- 加密與解密實戰全攻略