- React Design Patterns and Best Practices(Second Edition)
- Carlos Santana Roldán
- 121字
- 2021-06-24 15:43:38
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.
推薦閱讀
- 計算機網絡與通信(第2版)
- Proxmox High Availability
- 智慧城市中的移動互聯網技術
- 物聯網之霧:基于霧計算的智能硬件快速反應與安全控制
- IPv6網絡切片:使能千行百業新體驗
- Kong網關:入門、實戰與進階
- The Kubernetes Workshop
- Android UI Design
- Implementing NetScaler VPX?
- 5G時代的大數據技術架構和關鍵技術詳解
- Hands-On Reactive Programming in Spring 5
- Architecting Data:Intensive Applications
- 網絡空間作戰:機理與籌劃
- 視聽變革:廣電的新媒體戰略
- 網絡安全和信息化黨政領導干部一本通