官术网_书友最值得收藏!

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);
主站蜘蛛池模板: 英吉沙县| 永城市| 威宁| 十堰市| 南京市| 秦皇岛市| 乌拉特后旗| 望谟县| 华亭县| 长海县| 五指山市| 清流县| 张掖市| 景德镇市| 襄汾县| 西华县| 井研县| 漳平市| 扶风县| 泸定县| 沙雅县| 邹平县| 灵丘县| 宜宾市| 漯河市| 文化| 思南县| 文成县| 乳山市| 将乐县| 施秉县| 莎车县| 德州市| 遵义市| 闽侯县| 慈溪市| 鱼台县| 中超| 阳原县| 临泉县| 定远县|