- 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);
推薦閱讀
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 面向云平臺(tái)的物聯(lián)網(wǎng)多源異構(gòu)信息融合方法
- 數(shù)字通信同步技術(shù)的MATLAB與FPGA實(shí)現(xiàn):Altera/Verilog版(第2版)
- Building RESTful Web services with Go
- 智慧光網(wǎng)絡(luò):關(guān)鍵技術(shù)、應(yīng)用實(shí)踐和未來(lái)演進(jìn)
- 6G:面向2030年的移動(dòng)通信
- 端到端QoS網(wǎng)絡(luò)設(shè)計(jì)
- Selenium WebDriver 3 Practical Guide
- Getting Started with tmux
- 區(qū)塊鏈社區(qū)運(yùn)營(yíng)手冊(cè)
- React Design Patterns and Best Practices(Second Edition)
- 通信系統(tǒng)實(shí)戰(zhàn)筆記:無(wú)處不在的信號(hào)處理
- 黑客心理學(xué):社會(huì)工程學(xué)原理
- Hands-On Cloud:Native Microservices with Jakarta EE
- 互聯(lián)網(wǎng)戰(zhàn)略變革與未來(lái)