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

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.

主站蜘蛛池模板: 巨野县| 阿荣旗| 苏州市| 利津县| 永宁县| 平阴县| 类乌齐县| 西峡县| 沙坪坝区| 阿尔山市| 鹰潭市| 德格县| 平罗县| 定西市| 长治县| 凌源市| 临泉县| 沈丘县| 会泽县| 山丹县| 青海省| 鲁甸县| 潜江市| 观塘区| 天祝| 太仆寺旗| 西吉县| 平远县| 开平市| 蒙山县| 高密市| 缙云县| 甘肃省| 米易县| 冕宁县| 芦溪县| 沛县| 东乡族自治县| 什邡市| 永泰县| 雷波县|