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

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);
主站蜘蛛池模板: 双城市| 托克逊县| 佛冈县| 邛崃市| 海口市| 六安市| 汽车| 秭归县| 仁布县| 达孜县| 陈巴尔虎旗| 富源县| 锡林浩特市| 扶绥县| 康马县| 印江| 洪雅县| 尖扎县| 乌审旗| 宁明县| 两当县| 隆化县| 济南市| 印江| 温宿县| 剑川县| 黔东| 沙田区| 本溪| 连云港市| 会昌县| 屏南县| 南通市| 怀柔区| 兰州市| 施甸县| 东安县| 万安县| 定陶县| 沁源县| 左贡县|