- 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.
- 網(wǎng)絡(luò)協(xié)議工程
- Hands-On Industrial Internet of Things
- 5G承載網(wǎng)網(wǎng)絡(luò)規(guī)劃與組網(wǎng)設(shè)計
- 信息通信網(wǎng)絡(luò)建設(shè)安全管理概要2
- Getting Started with WebRTC
- CCNP TSHOOT(642-832)認證考試指南
- 網(wǎng)絡(luò)利他行為研究:積極心理學(xué)的視角
- Microsoft Power Platform Enterprise Architecture
- 園區(qū)網(wǎng)絡(luò)架構(gòu)與技術(shù)
- 移動互聯(lián)網(wǎng)新思維
- 物聯(lián)網(wǎng)與智慧廣電
- 想象的互動:網(wǎng)絡(luò)人際傳播中的印象形成
- Python Web Scraping Cookbook
- Microservices Development Cookbook
- 視聽變革:廣電的新媒體戰(zhàn)略