React

【React Tips/ 属性の有無をpropsで出し分ける】if component has props of id as trusy value, It will be add attribute of id. if not, will be remove attribute of id

[React Tips/ 属性の有無をpropsで出し分ける]if component has props of id as trusy value, It will be add attribute of id. if not, will be remove attribute of id

React
React

 

<div id={id & id}>Hello</div>

最近周りの人のコードで上のようなこのようなコードを見た

これだとidがtrueなら

<div id="a">Hello</div>

falseなら

<div id>Hello</div>

になるので、falsyなときに属性だけ残って気持ちが悪い

なのでそうならないためのTips

よくあるclassNameもこれで事前にできる。
例えばある値がtrueのときだけclassNameを付与するとか


「武骨日記の」プライバシーポリシーに関して
プライバシーポリシー

株式会社TerraceTechについて
最近起業しました。
株式会社TerraceTech

SNS
しずかなインターネット kenjimorita
インド旅 instagram
適当な日常写真 instagram
シュールさーん instagram
シュールさーん LINEスタンプ
もりたけんじTwitter
ネタ帳Twitter
note

FaceBook -kennji.morita-

わたしが結成しているWebチームではWeb未経験者、フリーランスの方へのお仕事を紹介しています。
また個人レッスンしてほしい生徒も募集中です。
もしご興味ある方はチャットからご連絡ください。

※業務連絡やお久しぶり連絡もチャットからお願いします。