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

Boolean attributes

A couple more things are worth mentioning before starting for real regarding the way you define Boolean attributes in JSX. If you set an attribute without a value, JSX assumes that its value is true, following the same behavior of the HTML disabled attribute, for example.

This means that if we want to set an attribute to false, we have to declare it explicitly as false:

  <button disabled /> 
React.createElement("button", { disabled: true });

The following is another example:

  <button disabled={false} /> 
React.createElement("button", { disabled: false });

This can be confusing in the beginning, because we may think that omitting an attribute would mean false, but it is not like that. With React, we should always be explicit to avoid confusion.

主站蜘蛛池模板: 延长县| 桐庐县| 昌黎县| 德庆县| 瑞丽市| 尚志市| 横峰县| 澄城县| 格尔木市| 长兴县| 玉环县| 兰州市| 滁州市| 隆德县| 葫芦岛市| 松阳县| 繁昌县| 安岳县| 永修县| 安岳县| 杭州市| 汉川市| 施甸县| 马龙县| 泰和县| 库伦旗| 千阳县| 合肥市| 武邑县| 离岛区| 河源市| 灌南县| 阿克陶县| 通化市| 江北区| 高台县| 巴彦县| 古蔺县| 任丘市| 天水市| 广平县|