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

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);
主站蜘蛛池模板: 田阳县| 平原县| 定南县| 娱乐| 永丰县| 镇平县| 怀仁县| 繁昌县| 南充市| 乐业县| 哈尔滨市| 蓬莱市| 武强县| 东平县| 望江县| 汉沽区| 米泉市| 新竹市| 昭觉县| 瑞金市| 嫩江县| 本溪| 青海省| 宜兰县| 广东省| 武宁县| 萨嘎县| 萨嘎县| 江城| 海口市| 东丽区| 固阳县| 义马市| 皮山县| 广灵县| 海林市| 金华市| 寻乌县| 高密市| 英山县| 弥渡县|