- React Design Patterns and Best Practices(Second Edition)
- Carlos Santana Roldán
- 119字
- 2021-06-24 15:43:38
Spread attributes
An important feature is the spread attribute operator (...), which comes from the rest/spread properties for ECMAScript proposal, and is very convenient whenever we want to pass all the attributes of a JavaScript object to an element.
A common practice that leads to fewer bugs is not to pass entire JavaScript objects down to children by reference, but to use their primitive values, which can be easily validated, making components more robust and error-proof.
Let's see how it works:
const attrs = {
id: 'myId',
className: 'myClass'
};
return <div {...attrs} />;
The preceding code gets transpiled into the following:
var attrs = {
id: 'myId',
className: 'myClass'
};
return React.createElement('div', attrs);
推薦閱讀
- 物聯(lián)網(wǎng)與北斗應(yīng)用
- 解析QUIC/HTTP3:未來(lái)互聯(lián)網(wǎng)的基石
- 工業(yè)控制網(wǎng)絡(luò)安全技術(shù)與實(shí)踐
- GPS/GNSS原理與應(yīng)用(第3版)
- 農(nóng)產(chǎn)品物聯(lián)網(wǎng)研究與應(yīng)用
- 新一代物聯(lián)網(wǎng)架構(gòu)技術(shù):分層算力網(wǎng)絡(luò)
- 物聯(lián)網(wǎng)信息安全
- SD-WAN架構(gòu)與技術(shù)(第2版)
- NB-IoT物聯(lián)網(wǎng)技術(shù)解析與案例詳解
- Mastering JavaFX 10
- 企業(yè)網(wǎng)絡(luò)安全管理
- Yii Application Development Cookbook(Second Edition)
- Learning Swift(Second Edition)
- Working with Legacy Systems
- 6G無(wú)線網(wǎng)絡(luò)空口關(guān)鍵技術(shù)