[英]skip passing props in jsx
如何不根據條件通過道具? 我可以做這個
const condition = true
<ThirdPartyComponent custom={() => condition ? <h1>hello<h1> : null}
但是ThirdPartyComponent仍然會為null,我想跳過將自定義屬性傳遞給ThirdPartyComponent。 請注意,我無權訪問ThirdPartyComponent。
根據條件渲染組件。 使用三元運算符,如果為true,則傳遞prop或在其他條件下不傳遞
你可以這樣-
const condition = true;
condition ? (<ThirdPartyComponent custom={value} />) : (<ThirdPartyComponent /> )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.