- React Design Patterns and Best Practices(Second Edition)
- Carlos Santana Roldán
- 151字
- 2021-06-24 15:43:39
Loops
A very common operation in UI development is to display lists of items. When it comes to showing lists, using JavaScript as a template language is a very good idea.
If we write a function that returns an array inside our JSX template, each element of the array gets compiled into an element.
As we have seen before, we can use any JavaScript expressions inside curly braces, and the most common way to generate an array of elements, given an array of objects, is to use map.
Let's dive into a real-world example. Suppose you have a list of users, each one with a name property attached to it.
To create an unordered list to show the users, you can do the following:
<ul>
{users.map(user => <li>{user.name}</li>)}
</ul>
This snippet is incredibly simple and incredibly powerful at the same time, where the power of the HTML and JavaScript converge.
- 通信網絡基礎與設備
- 工業(yè)控制網絡安全技術與實踐
- 社交電商運營策略、技巧與實操
- Go Web Scraping Quick Start Guide
- 面向物聯(lián)網的嵌入式系統(tǒng)開發(fā):基于CC2530和STM32微處理器
- CCNP TSHOOT(642-832)認證考試指南
- Echo Quick Start Guide
- INSTANT LinkedIn Customization How-to
- 全聯(lián)網標識服務
- 計算機通信網絡安全
- 物聯(lián)網M2M開發(fā)技術:基于無線CPU-Q26XX
- 走近奇妙的物聯(lián)網
- ReasonML Quick Start Guide
- 智能物聯(lián)安防視頻技術基礎與應用
- 互聯(lián)網戰(zhàn)略變革與未來